blob: bdf1b232087966e9cead6012635884491da3a1b5 [file] [log] [blame]
[email protected]8af4c1992010-02-04 21:38:071// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2362e4f2009-05-08 00:34:055#ifndef VIEWS_VIEW_H_
6#define VIEWS_VIEW_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]8c117712009-01-13 12:26:468#include "build/build_config.h"
9
[email protected]1bc83062009-02-06 00:16:3710#include <algorithm>
initial.commit09911bf2008-07-26 23:55:2911#include <map>
[email protected]134c47b92009-08-19 03:33:4412#include <set>
[email protected]1bc83062009-02-06 00:16:3713#include <string>
initial.commit09911bf2008-07-26 23:55:2914#include <vector>
15
[email protected]134c47b92009-08-19 03:33:4416#include "app/os_exchange_data.h"
initial.commit09911bf2008-07-26 23:55:2917#include "base/scoped_ptr.h"
[email protected]5c7293a2010-03-17 06:40:5718#include "gfx/native_widget_types.h"
[email protected]e0fc2f12010-03-14 23:30:5919#include "gfx/rect.h"
[email protected]2362e4f2009-05-08 00:34:0520#include "views/accelerator.h"
[email protected]91e81ae2009-05-08 22:14:3821#include "views/accessibility/accessibility_types.h"
[email protected]2362e4f2009-05-08 00:34:0522#include "views/background.h"
23#include "views/border.h"
initial.commit09911bf2008-07-26 23:55:2924
[email protected]1eb89e82008-08-15 12:27:0325namespace gfx {
[email protected]82522512009-05-15 07:37:2926class Canvas;
[email protected]1eb89e82008-08-15 12:27:0327class Insets;
[email protected]82739cf2008-09-16 00:37:5628class Path;
[email protected]1eb89e82008-08-15 12:27:0329}
30
[email protected]fef10642009-03-17 21:17:0431class ViewAccessibilityWrapper;
[email protected]4a190632009-05-09 01:07:4232class ThemeProvider;
initial.commit09911bf2008-07-26 23:55:2933
[email protected]c2dacc92008-10-16 23:51:3834namespace views {
initial.commit09911bf2008-07-26 23:55:2935
36class Background;
37class Border;
38class FocusManager;
39class FocusTraversable;
40class LayoutManager;
41class RestoreFocusTask;
42class RootView;
43class ScrollView;
[email protected]a0dde122008-11-21 20:51:2044class Widget;
[email protected]cd8c47902009-04-30 20:55:3545class Window;
initial.commit09911bf2008-07-26 23:55:2946
47// ContextMenuController is responsible for showing the context menu for a
48// View. To use a ContextMenuController invoke SetContextMenuController on a
49// View. When the appropriate user gesture occurs ShowContextMenu is invoked
50// on the ContextMenuController.
51//
52// Setting a ContextMenuController on a view makes the view process mouse
53// events.
54//
55// It is up to subclasses that do their own mouse processing to invoke
56// the appropriate ContextMenuController method, typically by invoking super's
57// implementation for mouse processing.
58//
59class ContextMenuController {
60 public:
[email protected]e9adf0702010-03-08 23:34:0761 // Invoked to show the context menu for the source view. If |is_mouse_gesture|
62 // is true, |p| is the location of the mouse. If |is_mouse_gesture| is false,
63 // this method was not invoked by a mouse gesture and |p| is the recommended
64 // location to show the menu at.
initial.commit09911bf2008-07-26 23:55:2965 //
[email protected]e9adf0702010-03-08 23:34:0766 // |p| is in screen coordinates.
initial.commit09911bf2008-07-26 23:55:2967 virtual void ShowContextMenu(View* source,
[email protected]e9adf0702010-03-08 23:34:0768 const gfx::Point& p,
initial.commit09911bf2008-07-26 23:55:2969 bool is_mouse_gesture) = 0;
[email protected]20cb5f482009-12-16 01:01:2570
71 protected:
72 virtual ~ContextMenuController() {}
initial.commit09911bf2008-07-26 23:55:2973};
74
75// DragController is responsible for writing drag data for a view, as well as
76// supplying the supported drag operations. Use DragController if you don't
77// want to subclass.
78
79class DragController {
80 public:
81 // Writes the data for the drag.
82 virtual void WriteDragData(View* sender,
[email protected]e9adf0702010-03-08 23:34:0783 const gfx::Point& press_pt,
initial.commit09911bf2008-07-26 23:55:2984 OSExchangeData* data) = 0;
85
86 // Returns the supported drag operations (see DragDropTypes for possible
87 // values). A drag is only started if this returns a non-zero value.
[email protected]e9adf0702010-03-08 23:34:0788 virtual int GetDragOperations(View* sender, const gfx::Point& p) = 0;
initial.commit09911bf2008-07-26 23:55:2989
[email protected]b5f94de2009-12-04 07:59:0090 // Returns true if a drag operation can be started.
[email protected]e9adf0702010-03-08 23:34:0791 // |press_pt| represents the coordinates where the mouse was initially
92 // pressed down. |p| is the current mouse coordinates.
[email protected]b5f94de2009-12-04 07:59:0093 virtual bool CanStartDrag(View* sender,
[email protected]e9adf0702010-03-08 23:34:0794 const gfx::Point& press_pt,
95 const gfx::Point& p) = 0;
[email protected]20cb5f482009-12-16 01:01:2596
97 protected:
98 virtual ~DragController() {}
[email protected]b5f94de2009-12-04 07:59:0099};
initial.commit09911bf2008-07-26 23:55:29100
101/////////////////////////////////////////////////////////////////////////////
102//
103// View class
104//
[email protected]c2dacc92008-10-16 23:51:38105// A View is a rectangle within the views View hierarchy. It is the base
[email protected]1bc83062009-02-06 00:16:37106// class for all Views.
initial.commit09911bf2008-07-26 23:55:29107//
108// A View is a container of other Views (there is no such thing as a Leaf
109// View - makes code simpler, reduces type conversion headaches, design
110// mistakes etc)
111//
112// The View contains basic properties for sizing (bounds), layout (flex,
113// orientation, etc), painting of children and event dispatch.
114//
115// The View also uses a simple Box Layout Manager similar to XUL's
116// SprocketLayout system. Alternative Layout Managers implementing the
117// LayoutManager interface can be used to lay out children if required.
118//
119// It is up to the subclass to implement Painting and storage of subclass -
120// specific properties and functionality.
121//
122/////////////////////////////////////////////////////////////////////////////
123class View : public AcceleratorTarget {
124 public:
[email protected]6f3bb6c2008-09-17 22:25:33125 // Used in the versions of GetBounds() and x() that take a transformation
initial.commit09911bf2008-07-26 23:55:29126 // parameter in order to determine whether or not to take into account the
127 // mirroring setting of the View when returning bounds positions.
128 enum PositionMirroringSettings {
129 IGNORE_MIRRORING_TRANSFORMATION = 0,
130 APPLY_MIRRORING_TRANSFORMATION
131 };
132
133 // The view class name.
134 static char kViewClassName[];
135
136 View();
137 virtual ~View();
138
[email protected]aadcd1d92009-09-22 18:11:31139 // Returns the amount of time between double clicks, in milliseconds.
140 static int GetDoubleClickTimeMS();
141
[email protected]8af4c1992010-02-04 21:38:07142 // Returns the amount of time to wait from hovering over a menu button until
143 // showing the menu.
144 static int GetMenuShowDelay();
145
initial.commit09911bf2008-07-26 23:55:29146 // Sizing functions
147
148 // Get the bounds of the View, relative to the parent. Essentially, this
149 // function returns the bounds_ rectangle.
150 //
151 // This is the function subclasses should use whenever they need to obtain
152 // the bounds of one of their child views (for example, when implementing
153 // View::Layout()).
[email protected]24db2eb2009-07-17 17:54:16154 const gfx::Rect& bounds() const { return bounds_; }
[email protected]80f8b9f2008-10-16 18:17:47155
156 // Get the size of the View.
[email protected]24db2eb2009-07-17 17:54:16157 const gfx::Size& size() const { return bounds_.size(); }
initial.commit09911bf2008-07-26 23:55:29158
159 // Return the bounds of the View, relative to the parent. If
160 // |settings| is IGNORE_MIRRORING_TRANSFORMATION, the function returns the
[email protected]8f763a302009-11-11 00:47:32161 // bounds_ rectangle. If |settings| is APPLY_MIRRORING_TRANSFORMATION AND the
initial.commit09911bf2008-07-26 23:55:29162 // parent View is using a right-to-left UI layout, then the function returns
163 // a shifted version of the bounds_ rectangle that represents the mirrored
164 // View bounds.
165 //
166 // NOTE: in the vast majority of the cases, the mirroring implementation is
167 // transparent to the View subclasses and therefore you should use the
168 // version of GetBounds() which does not take a transformation settings
169 // parameter.
[email protected]0d8ea702008-10-14 17:03:07170 gfx::Rect GetBounds(PositionMirroringSettings settings) const;
initial.commit09911bf2008-07-26 23:55:29171
172 // Set the bounds in the parent's coordinate system.
[email protected]80f8b9f2008-10-16 18:17:47173 void SetBounds(const gfx::Rect& bounds);
174 void SetBounds(int x, int y, int width, int height) {
175 SetBounds(gfx::Rect(x, y, std::max(0, width), std::max(0, height)));
176 }
[email protected]6f3bb6c2008-09-17 22:25:33177 void SetX(int x) { SetBounds(x, y(), width(), height()); }
178 void SetY(int y) { SetBounds(x(), y, width(), height()); }
initial.commit09911bf2008-07-26 23:55:29179
180 // Returns the left coordinate of the View, relative to the parent View,
[email protected]80f8b9f2008-10-16 18:17:47181 // which is the value of bounds_.x().
initial.commit09911bf2008-07-26 23:55:29182 //
183 // This is the function subclasses should use whenever they need to obtain
184 // the left position of one of their child views (for example, when
185 // implementing View::Layout()).
[email protected]0a1d36b22008-10-17 19:33:09186 // This is equivalent to GetX(IGNORE_MIRRORING_TRANSFORMATION), but
187 // inlinable.
188 int x() const { return bounds_.x(); }
189 int y() const { return bounds_.y(); }
190 int width() const { return bounds_.width(); }
191 int height() const { return bounds_.height(); }
initial.commit09911bf2008-07-26 23:55:29192
193 // Return the left coordinate of the View, relative to the parent. If
194 // |settings| is IGNORE_MIRRORING_SETTINGS, the function returns the value of
[email protected]80f8b9f2008-10-16 18:17:47195 // bounds_.x(). If |settings| is APPLY_MIRRORING_SETTINGS AND the parent
initial.commit09911bf2008-07-26 23:55:29196 // View is using a right-to-left UI layout, then the function returns the
[email protected]80f8b9f2008-10-16 18:17:47197 // mirrored value of bounds_.x().
initial.commit09911bf2008-07-26 23:55:29198 //
199 // NOTE: in the vast majority of the cases, the mirroring implementation is
200 // transparent to the View subclasses and therefore you should use the
[email protected]6f3bb6c2008-09-17 22:25:33201 // paremeterless version of x() when you need to get the X
initial.commit09911bf2008-07-26 23:55:29202 // coordinate of a child View.
203 int GetX(PositionMirroringSettings settings) const;
204
initial.commit09911bf2008-07-26 23:55:29205 // Return this control local bounds. If include_border is true, local bounds
[email protected]6f3bb6c2008-09-17 22:25:33206 // is the rectangle {0, 0, width(), height()}, otherwise, it does not
initial.commit09911bf2008-07-26 23:55:29207 // include the area where the border (if any) is painted.
[email protected]80f8b9f2008-10-16 18:17:47208 gfx::Rect GetLocalBounds(bool include_border) const;
initial.commit09911bf2008-07-26 23:55:29209
210 // Get the position of the View, relative to the parent.
211 //
212 // Note that if the parent uses right-to-left UI layout, then the mirrored
[email protected]6f3bb6c2008-09-17 22:25:33213 // position of this View is returned. Use x()/y() if you want to ignore
initial.commit09911bf2008-07-26 23:55:29214 // mirroring.
[email protected]0a1d36b22008-10-17 19:33:09215 gfx::Point GetPosition() const;
initial.commit09911bf2008-07-26 23:55:29216
217 // Get the size the View would like to be, if enough space were available.
[email protected]154f8bc2008-10-15 18:02:30218 virtual gfx::Size GetPreferredSize();
initial.commit09911bf2008-07-26 23:55:29219
[email protected]a1360162009-11-30 21:19:07220 // Returns the baseline of this view, or -1 if this view has no baseline. The
221 // return value is relative to the preferred height.
222 virtual int GetBaseline();
223
initial.commit09911bf2008-07-26 23:55:29224 // Convenience method that sizes this view to its preferred size.
225 void SizeToPreferredSize();
226
227 // Gets the minimum size of the view. View's implementation invokes
228 // GetPreferredSize.
[email protected]154f8bc2008-10-15 18:02:30229 virtual gfx::Size GetMinimumSize();
initial.commit09911bf2008-07-26 23:55:29230
231 // Return the height necessary to display this view with the provided width.
232 // View's implementation returns the value from getPreferredSize.cy.
233 // Override if your View's preferred height depends upon the width (such
234 // as with Labels).
235 virtual int GetHeightForWidth(int w);
236
237 // This method is invoked when this object size or position changes.
238 // The default implementation does nothing.
[email protected]80f8b9f2008-10-16 18:17:47239 virtual void DidChangeBounds(const gfx::Rect& previous,
240 const gfx::Rect& current);
initial.commit09911bf2008-07-26 23:55:29241
242 // Set whether the receiving view is visible. Painting is scheduled as needed
243 virtual void SetVisible(bool flag);
244
245 // Return whether a view is visible
246 virtual bool IsVisible() const { return is_visible_; }
247
248 // Return whether a view and its ancestors are visible. Returns true if the
249 // path from this view to the root view is visible.
250 virtual bool IsVisibleInRootView() const;
251
252 // Set whether this view is enabled. A disabled view does not receive keyboard
253 // or mouse inputs. If flag differs from the current value, SchedulePaint is
254 // invoked.
255 virtual void SetEnabled(bool flag);
256
257 // Returns whether the view is enabled.
258 virtual bool IsEnabled() const;
259
260 // Set whether this view is hottracked. A disabled view cannot be hottracked.
261 // If flag differs from the current value, SchedulePaint is invoked.
262 virtual void SetHotTracked(bool flag);
263
264 // Returns whether the view is hot-tracked.
265 virtual bool IsHotTracked() const { return false; }
266
267 // Returns whether the view is pushed.
268 virtual bool IsPushed() const { return false; }
269
270 // Scrolls the specified region, in this View's coordinate system, to be
271 // visible. View's implementation passes the call onto the parent View (after
272 // adjusting the coordinates). It is up to views that only show a portion of
273 // the child view, such as Viewport, to override appropriately.
[email protected]e9adf0702010-03-08 23:34:07274 virtual void ScrollRectToVisible(const gfx::Rect& rect);
initial.commit09911bf2008-07-26 23:55:29275
276 // Layout functions
277
278 // Lay out the child Views (set their bounds based on sizing heuristics
279 // specific to the current Layout Manager)
280 virtual void Layout();
281
282 // Gets/Sets the Layout Manager used by this view to size and place its
283 // children.
284 // The LayoutManager is owned by the View and is deleted when the view is
285 // deleted, or when a new LayoutManager is installed.
286 LayoutManager* GetLayoutManager() const;
287 void SetLayoutManager(LayoutManager* layout);
288
289 // Right-to-left UI layout functions
290
291 // Indicates whether the UI layout for this view is right-to-left. The view
292 // has an RTL UI layout if RTL hasn't been disabled for the view and if the
293 // locale's language is an RTL language.
[email protected]1eb89e82008-08-15 12:27:03294 bool UILayoutIsRightToLeft() const;
initial.commit09911bf2008-07-26 23:55:29295
296 // Enables or disables the right-to-left layout for the view. If |enable| is
297 // true, the layout will become right-to-left only if the locale's language
298 // is right-to-left.
299 //
300 // By default, right-to-left UI layout is enabled for the view and therefore
301 // this function must be called (with false as the |enable| parameter) in
302 // order to disable the right-to-left layout property for a specific instance
303 // of the view. Disabling the right-to-left UI layout is necessary in case a
304 // UI element will not appear correctly when mirrored.
305 void EnableUIMirroringForRTLLanguages(bool enable) {
306 ui_mirroring_is_enabled_for_rtl_languages_ = enable;
307 }
308
[email protected]82522512009-05-15 07:37:29309 // This method determines whether the gfx::Canvas object passed to
initial.commit09911bf2008-07-26 23:55:29310 // View::Paint() needs to be transformed such that anything drawn on the
311 // canvas object during View::Paint() is flipped horizontally.
312 //
313 // By default, this function returns false (which is the initial value of
314 // |flip_canvas_on_paint_for_rtl_ui_|). View subclasses that need to paint on
[email protected]82522512009-05-15 07:37:29315 // a flipped gfx::Canvas when the UI layout is right-to-left need to call
initial.commit09911bf2008-07-26 23:55:29316 // EnableCanvasFlippingForRTLUI().
317 bool FlipCanvasOnPaintForRTLUI() const {
318 return flip_canvas_on_paint_for_rtl_ui_ ? UILayoutIsRightToLeft() : false;
319 }
320
[email protected]82522512009-05-15 07:37:29321 // Enables or disables flipping of the gfx::Canvas during View::Paint().
initial.commit09911bf2008-07-26 23:55:29322 // Note that if canvas flipping is enabled, the canvas will be flipped only
323 // if the UI layout is right-to-left; that is, the canvas will be flipped
324 // only if UILayoutIsRightToLeft() returns true.
325 //
326 // Enabling canvas flipping is useful for leaf views that draw a bitmap that
327 // needs to be flipped horizontally when the UI layout is right-to-left
[email protected]c2dacc92008-10-16 23:51:38328 // (views::Button, for example). This method is helpful for such classes
329 // because their drawing logic stays the same and they can become agnostic to
330 // the UI directionality.
initial.commit09911bf2008-07-26 23:55:29331 void EnableCanvasFlippingForRTLUI(bool enable) {
332 flip_canvas_on_paint_for_rtl_ui_ = enable;
333 }
334
335 // Returns the mirrored X position for the view, relative to the parent. If
336 // the parent view is not mirrored, this function returns bound_.left.
337 //
338 // UI mirroring is transparent to most View subclasses and therefore there is
339 // no need to call this routine from anywhere within your subclass
340 // implementation.
[email protected]63329982008-10-10 21:56:57341 int MirroredX() const;
initial.commit09911bf2008-07-26 23:55:29342
343 // Given a rectangle specified in this View's coordinate system, the function
344 // computes the 'left' value for the mirrored rectangle within this View. If
345 // the View's UI layout is not right-to-left, then bounds.x() is returned.
346 //
347 // UI mirroring is transparent to most View subclasses and therefore there is
348 // no need to call this routine from anywhere within your subclass
349 // implementation.
350 int MirroredLeftPointForRect(const gfx::Rect& rect) const;
351
352 // Given the X coordinate of a point inside the View, this function returns
353 // the mirrored X coordinate of the point if the View's UI layout is
354 // right-to-left. If the layout is left-to-right, the same X coordinate is
355 // returned.
356 //
357 // Following are a few examples of the values returned by this function for
358 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout:
359 //
360 // MirroredXCoordinateInsideView(0) -> 100
361 // MirroredXCoordinateInsideView(20) -> 80
362 // MirroredXCoordinateInsideView(99) -> 1
363 int MirroredXCoordinateInsideView(int x) const {
[email protected]6f3bb6c2008-09-17 22:25:33364 return UILayoutIsRightToLeft() ? width() - x : x;
initial.commit09911bf2008-07-26 23:55:29365 }
366
[email protected]14da3dff2009-06-12 18:01:47367 // Given a X coordinate and a width inside the View, this function returns
368 // the mirrored X coordinate if the View's UI layout is right-to-left. If the
369 // layout is left-to-right, the same X coordinate is returned.
370 //
371 // Following are a few examples of the values returned by this function for
372 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout:
373 //
374 // MirroredXCoordinateInsideView(0, 10) -> 90
375 // MirroredXCoordinateInsideView(20, 20) -> 60
376 int MirroredXWithWidthInsideView(int x, int w) const {
377 return UILayoutIsRightToLeft() ? width() - x - w : x;
378 }
379
initial.commit09911bf2008-07-26 23:55:29380 // Painting functions
381
382 // Mark the specified rectangle as dirty (needing repaint). If |urgent| is
383 // true, the view will be repainted when the current event processing is
384 // done. Otherwise, painting will take place as soon as possible.
[email protected]0a1d36b22008-10-17 19:33:09385 virtual void SchedulePaint(const gfx::Rect& r, bool urgent);
initial.commit09911bf2008-07-26 23:55:29386
387 // Mark the entire View's bounds as dirty. Painting will occur as soon as
388 // possible.
389 virtual void SchedulePaint();
390
initial.commit09911bf2008-07-26 23:55:29391 // Paint the receiving view. g is prepared such as it is in
392 // receiver's coordinate system. g's state is restored after this
393 // call so your implementation can change the graphics configuration
394 //
395 // Default implementation paints the background if it is defined
396 //
397 // Override this method when implementing a new control.
[email protected]82522512009-05-15 07:37:29398 virtual void Paint(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29399
400 // Paint the background if any. This method is called by Paint() and
401 // should rarely be invoked directly.
[email protected]82522512009-05-15 07:37:29402 virtual void PaintBackground(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29403
404 // Paint the border if any. This method is called by Paint() and
405 // should rarely be invoked directly.
[email protected]82522512009-05-15 07:37:29406 virtual void PaintBorder(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29407
408 // Paints the focus border (only if the view has the focus).
409 // This method is called by Paint() and should rarely be invoked directly.
410 // The default implementation paints a gray border around the view. Override
411 // it for custom focus effects.
[email protected]82522512009-05-15 07:37:29412 virtual void PaintFocusBorder(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29413
414 // Paint this View immediately.
415 virtual void PaintNow();
416
initial.commit09911bf2008-07-26 23:55:29417 // Tree functions
418
419 // Add a child View.
420 void AddChildView(View* v);
421
422 // Adds a child View at the specified position.
423 void AddChildView(int index, View* v);
424
425 // Get the child View at the specified index.
426 View* GetChildViewAt(int index) const;
427
428 // Remove a child view from this view. v's parent will change to NULL
429 void RemoveChildView(View *v);
430
431 // Remove all child view from this view. If |delete_views| is true, the views
432 // are deleted, unless marked as not parent owned.
433 void RemoveAllChildViews(bool delete_views);
434
435 // Get the number of child Views.
436 int GetChildViewCount() const;
437
[email protected]3a9c26f2010-03-12 21:04:39438 // Tests if this view has a given view as direct child.
439 bool HasChildView(View* a_view);
440
[email protected]24db2eb2009-07-17 17:54:16441 // Returns the deepest descendant that contains the specified point.
[email protected]613b8062008-10-14 23:45:09442 virtual View* GetViewForPoint(const gfx::Point& point);
initial.commit09911bf2008-07-26 23:55:29443
[email protected]a0dde122008-11-21 20:51:20444 // Get the Widget that hosts this View, if any.
445 virtual Widget* GetWidget() const;
initial.commit09911bf2008-07-26 23:55:29446
[email protected]cd8c47902009-04-30 20:55:35447 // Gets the Widget that most closely contains this View, if any.
[email protected]08a3b712009-10-14 18:03:47448 // NOTE: almost all views displayed on screen have a Widget, but not
449 // necessarily a Window. This is due to widgets being able to create top
450 // level windows (as is done for popups, bubbles and menus).
[email protected]cd8c47902009-04-30 20:55:35451 virtual Window* GetWindow() const;
452
[email protected]2db27be2010-02-10 22:46:47453 // Returns true if the native view |native_view| is contained in the view
454 // hierarchy beneath this view.
455 virtual bool ContainsNativeView(gfx::NativeView native_view) const;
456
initial.commit09911bf2008-07-26 23:55:29457 // Get the containing RootView
458 virtual RootView* GetRootView();
459
460 // Get the parent View
461 View* GetParent() const { return parent_; }
462
463 // Returns the index of the specified |view| in this view's children, or -1
464 // if the specified view is not a child of this view.
465 int GetChildIndex(View* v) const;
466
467 // Returns true if the specified view is a direct or indirect child of this
468 // view.
469 bool IsParentOf(View* v) const;
470
471 // Recursively descends the view tree starting at this view, and returns
472 // the first child that it encounters that has the given ID.
473 // Returns NULL if no matching child view is found.
474 virtual View* GetViewByID(int id) const;
475
476 // Sets and gets the ID for this view. ID should be unique within the subtree
477 // that you intend to search for it. 0 is the default ID for views.
478 void SetID(int id);
479 int GetID() const;
480
481 // A group id is used to tag views which are part of the same logical group.
482 // Focus can be moved between views with the same group using the arrow keys.
483 // Groups are currently used to implement radio button mutual exclusion.
[email protected]96f960d2009-09-14 18:45:30484 // The group id is immutable once it's set.
initial.commit09911bf2008-07-26 23:55:29485 void SetGroup(int gid);
[email protected]96f960d2009-09-14 18:45:30486 // Returns the group id of the view, or -1 if the id is not set yet.
initial.commit09911bf2008-07-26 23:55:29487 int GetGroup() const;
488
489 // If this returns true, the views from the same group can each be focused
490 // when moving focus with the Tab/Shift-Tab key. If this returns false,
491 // only the selected view from the group (obtained with
492 // GetSelectedViewForGroup()) is focused.
493 virtual bool IsGroupFocusTraversable() const { return true; }
494
495 // Fills the provided vector with all the available views which belong to the
496 // provided group.
497 void GetViewsWithGroup(int group_id, std::vector<View*>* out);
498
499 // Return the View that is currently selected in the specified group.
500 // The default implementation simply returns the first View found for that
501 // group.
502 virtual View* GetSelectedViewForGroup(int group_id);
503
504 // Focus support
505 //
506 // Returns the view that should be selected next when pressing Tab.
507 View* GetNextFocusableView();
508
509 // Returns the view that should be selected next when pressing Shift-Tab.
510 View* GetPreviousFocusableView();
511
512 // Sets the component that should be selected next when pressing Tab, and
513 // makes the current view the precedent view of the specified one.
514 // Note that by default views are linked in the order they have been added to
515 // their container. Use this method if you want to modify the order.
516 // IMPORTANT NOTE: loops in the focus hierarchy are not supported.
517 void SetNextFocusableView(View* view);
518
519 // Return whether this view can accept the focus.
520 virtual bool IsFocusable() const;
521
522 // Sets whether this view can accept the focus.
523 // Note that this is false by default so that a view used as a container does
524 // not get the focus.
525 virtual void SetFocusable(bool focusable);
526
527 // Convenience method to retrieve the FocusManager associated with the
[email protected]a0dde122008-11-21 20:51:20528 // Widget that contains this view. This can return NULL if this view is not
529 // part of a view hierarchy with a Widget.
initial.commit09911bf2008-07-26 23:55:29530 virtual FocusManager* GetFocusManager();
531
532 // Sets a keyboard accelerator for that view. When the user presses the
533 // accelerator key combination, the AcceleratorPressed method is invoked.
534 // Note that you can set multiple accelerators for a view by invoking this
535 // method several times.
536 virtual void AddAccelerator(const Accelerator& accelerator);
537
[email protected]e8e0f362008-11-08 01:13:25538 // Removes the specified accelerator for this view.
539 virtual void RemoveAccelerator(const Accelerator& accelerator);
540
initial.commit09911bf2008-07-26 23:55:29541 // Removes all the keyboard accelerators for this view.
542 virtual void ResetAccelerators();
543
544 // Called when a keyboard accelerator is pressed.
545 // Derived classes should implement desired behavior and return true if they
546 // handled the accelerator.
547 virtual bool AcceleratorPressed(const Accelerator& accelerator) {
548 return false;
549 }
550
initial.commit09911bf2008-07-26 23:55:29551 // Returns whether this view currently has the focus.
552 virtual bool HasFocus();
553
554 // Accessibility support
555 // TODO(klink): Move all this out to a AccessibleInfo wrapper class.
556 //
557 // Returns the MSAA default action of the current view. The string returned
558 // describes the default action that will occur when executing
559 // IAccessible::DoDefaultAction. For instance, default action of a button is
560 // 'Press'. Sets the input string appropriately, and returns true if
561 // successful.
562 virtual bool GetAccessibleDefaultAction(std::wstring* action) {
563 return false;
564 }
565
566 // Returns a string containing the mnemonic, or the keyboard shortcut, for a
567 // given control. Sets the input string appropriately, and returns true if
568 // successful.
569 virtual bool GetAccessibleKeyboardShortcut(std::wstring* shortcut) {
570 return false;
571 }
572
573 // Returns a brief, identifying string, containing a unique, readable name of
574 // a given control. Sets the input string appropriately, and returns true if
575 // successful.
[email protected]d5c81012010-04-03 00:56:12576 bool GetAccessibleName(std::wstring* name);
initial.commit09911bf2008-07-26 23:55:29577
[email protected]e92070ac2009-04-28 00:12:01578 // Returns the accessibility role of the current view. The role is what
579 // assistive technologies (ATs) use to determine what behavior to expect from
580 // a given control. Sets the input Role appropriately, and returns true if
initial.commit09911bf2008-07-26 23:55:29581 // successful.
[email protected]e92070ac2009-04-28 00:12:01582 virtual bool GetAccessibleRole(AccessibilityTypes::Role* role) {
583 return false;
584 }
initial.commit09911bf2008-07-26 23:55:29585
[email protected]e92070ac2009-04-28 00:12:01586 // Returns the accessibility state of the current view. Sets the input State
587 // appropriately, and returns true if successful.
588 virtual bool GetAccessibleState(AccessibilityTypes::State* state) {
589 return false;
590 }
initial.commit09911bf2008-07-26 23:55:29591
[email protected]a9d59462010-03-26 21:51:04592 // Returns the current value associated with a view. Sets the input string
593 // appropriately, and returns true if successful.
594 virtual bool GetAccessibleValue(std::wstring* value) { return false; }
595
initial.commit09911bf2008-07-26 23:55:29596 // Assigns a string name to the given control. Needed as a View does not know
597 // which name will be associated with it until it is created to be a
598 // certain type.
[email protected]d5c81012010-04-03 00:56:12599 void SetAccessibleName(const std::wstring& name);
[email protected]a9d59462010-03-26 21:51:04600
initial.commit09911bf2008-07-26 23:55:29601 // Returns an instance of a wrapper class implementing the (platform-specific)
602 // accessibility interface for a given View. If one exists, it will be
603 // re-used, otherwise a new instance will be created.
[email protected]fef10642009-03-17 21:17:04604 ViewAccessibilityWrapper* GetViewAccessibilityWrapper();
initial.commit09911bf2008-07-26 23:55:29605
606 // Accessor used to determine if a child view (leaf) has accessibility focus.
607 // Returns NULL if there are no children, or if none of the children has
608 // accessibility focus.
[email protected]c2dacc92008-10-16 23:51:38609 virtual View* GetAccFocusedChildView() { return NULL; }
initial.commit09911bf2008-07-26 23:55:29610
[email protected]cc824372010-03-31 15:33:01611 // Try to give accessibility focus to a given child view. Returns true on
612 // success. Returns false if this view isn't already focused, if it doesn't
613 // support accessibility focus for children, or if the given view isn't a
614 // valid child view that can receive accessibility focus.
615 virtual bool SetAccFocusedChildView(View* child_view) { return false; }
616
initial.commit09911bf2008-07-26 23:55:29617 // Utility functions
618
619 // Note that the utility coordinate conversions functions always operate on
620 // the mirrored position of the child Views if the parent View uses a
621 // right-to-left UI layout.
622
623 // Convert a point from source coordinate system to dst coordinate system.
624 //
625 // source is a parent or a child of dst, directly or transitively.
626 // If source and dst are not in the same View hierarchy, the result is
627 // undefined.
628 // Source can be NULL in which case it means the screen coordinate system
[email protected]bb515ed2009-01-15 00:53:43629 static void ConvertPointToView(const View* src,
630 const View* dst,
initial.commit09911bf2008-07-26 23:55:29631 gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29632
633 // Convert a point from the coordinate system of a View to that of the
[email protected]a0dde122008-11-21 20:51:20634 // Widget. This is useful for example when sizing HWND children of the
635 // Widget that don't know about the View hierarchy and need to be placed
636 // relative to the Widget that is their parent.
[email protected]2fb6d462009-02-13 18:40:10637 static void ConvertPointToWidget(const View* src, gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29638
[email protected]a0dde122008-11-21 20:51:20639 // Convert a point from a view Widget to a View dest
[email protected]2fb6d462009-02-13 18:40:10640 static void ConvertPointFromWidget(const View* dest, gfx::Point* p);
initial.commit09911bf2008-07-26 23:55:29641
642 // Convert a point from the coordinate system of a View to that of the
643 // screen. This is useful for example when placing popup windows.
[email protected]2fb6d462009-02-13 18:40:10644 static void ConvertPointToScreen(const View* src, gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29645
646 // Event Handlers
647
648 // This method is invoked when the user clicks on this view.
649 // The provided event is in the receiver's coordinate system.
650 //
651 // Return true if you processed the event and want to receive subsequent
652 // MouseDraggged and MouseReleased events. This also stops the event from
653 // bubbling. If you return false, the event will bubble through parent
654 // views.
655 //
656 // If you remove yourself from the tree while processing this, event bubbling
657 // stops as if you returned true, but you will not receive future events.
658 // The return value is ignored in this case.
659 //
660 // Default implementation returns true if a ContextMenuController has been
661 // set, false otherwise. Override as needed.
662 //
663 virtual bool OnMousePressed(const MouseEvent& event);
664
665 // This method is invoked when the user clicked on this control.
666 // and is still moving the mouse with a button pressed.
667 // The provided event is in the receiver's coordinate system.
668 //
669 // Return true if you processed the event and want to receive
670 // subsequent MouseDragged and MouseReleased events.
671 //
672 // Default implementation returns true if a ContextMenuController has been
673 // set, false otherwise. Override as needed.
674 //
675 virtual bool OnMouseDragged(const MouseEvent& event);
676
677 // This method is invoked when the user releases the mouse
678 // button. The event is in the receiver's coordinate system.
679 //
680 // If canceled is true it indicates the mouse press/drag was canceled by a
681 // system/user gesture.
682 //
683 // Default implementation notifies the ContextMenuController is appropriate.
684 // Subclasses that wish to honor the ContextMenuController should invoke
685 // super.
686 virtual void OnMouseReleased(const MouseEvent& event, bool canceled);
687
688 // This method is invoked when the mouse is above this control
689 // The event is in the receiver's coordinate system.
690 //
691 // Default implementation does nothing. Override as needed.
692 virtual void OnMouseMoved(const MouseEvent& e);
693
694 // This method is invoked when the mouse enters this control.
695 //
696 // Default implementation does nothing. Override as needed.
697 virtual void OnMouseEntered(const MouseEvent& event);
698
699 // This method is invoked when the mouse exits this control
700 // The provided event location is always (0, 0)
701 // Default implementation does nothing. Override as needed.
702 virtual void OnMouseExited(const MouseEvent& event);
703
704 // Set the MouseHandler for a drag session.
705 //
706 // A drag session is a stream of mouse events starting
707 // with a MousePressed event, followed by several MouseDragged
708 // events and finishing with a MouseReleased event.
709 //
710 // This method should be only invoked while processing a
711 // MouseDragged or MouseReleased event.
712 //
713 // All further mouse dragged and mouse up events will be sent
714 // the MouseHandler, even if it is reparented to another window.
715 //
716 // The MouseHandler is automatically cleared when the control
717 // comes back from processing the MouseReleased event.
718 //
719 // Note: if the mouse handler is no longer connected to a
720 // view hierarchy, events won't be sent.
721 //
722 virtual void SetMouseHandler(View* new_mouse_handler);
723
724 // Request the keyboard focus. The receiving view will become the
725 // focused view.
726 virtual void RequestFocus();
727
728 // Invoked when a view is about to gain focus
729 virtual void WillGainFocus();
730
731 // Invoked when a view just gained focus.
732 virtual void DidGainFocus();
733
734 // Invoked when a view is about lose focus
735 virtual void WillLoseFocus();
736
737 // Invoked when a view is about to be requested for focus due to the focus
738 // traversal. Reverse is this request was generated going backward
739 // (Shift-Tab).
740 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) { }
741
[email protected]ca13d804c2009-05-14 04:28:07742 // Invoked when a key is pressed before the key event is processed (and
743 // potentially eaten) by the focus manager for tab traversal, accelerators and
744 // other focus related actions.
745 // The default implementation returns false, ensuring that tab traversal and
746 // accelerators processing is performed.
747 // Subclasses should return true if they want to process the key event and not
748 // have it processed as an accelerator (if any) or as a tab traversal (if the
749 // key event is for the TAB key). In that case, OnKeyPressed will
750 // subsequently be invoked for that event.
751 virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& e) {
752 return false;
753 }
754
initial.commit09911bf2008-07-26 23:55:29755 // Invoked when a key is pressed or released.
756 // Subclasser should return true if the event has been processed and false
757 // otherwise. If the event has not been processed, the parent will be given a
758 // chance.
759 virtual bool OnKeyPressed(const KeyEvent& e);
760 virtual bool OnKeyReleased(const KeyEvent& e);
761
initial.commit09911bf2008-07-26 23:55:29762 // Invoked when the user uses the mousewheel. Implementors should return true
763 // if the event has been processed and false otherwise. This message is sent
764 // if the view is focused. If the event has not been processed, the parent
765 // will be given a chance.
766 virtual bool OnMouseWheel(const MouseWheelEvent& e);
767
768 // Drag and drop functions.
769
770 // Set/get the DragController. See description of DragController for more
771 // information.
772 void SetDragController(DragController* drag_controller);
773 DragController* GetDragController();
774
775 // During a drag and drop session when the mouse moves the view under the
[email protected]134c47b92009-08-19 03:33:44776 // mouse is queried for the drop types it supports by way of the
777 // GetDropFormats methods. If the view returns true and the drag site can
778 // provide data in one of the formats, the view is asked if the drop data
779 // is required before any other drop events are sent. Once the
780 // data is available the view is asked if it supports the drop (by way of
781 // the CanDrop method). If a view returns true from CanDrop,
initial.commit09911bf2008-07-26 23:55:29782 // OnDragEntered is sent to the view when the mouse first enters the view,
783 // as the mouse moves around within the view OnDragUpdated is invoked.
784 // If the user releases the mouse over the view and OnDragUpdated returns a
785 // valid drop, then OnPerformDrop is invoked. If the mouse moves outside the
786 // view or over another view that wants the drag, OnDragExited is invoked.
787 //
788 // Similar to mouse events, the deepest view under the mouse is first checked
789 // if it supports the drop (Drop). If the deepest view under
790 // the mouse does not support the drop, the ancestors are walked until one
791 // is found that supports the drop.
792
[email protected]134c47b92009-08-19 03:33:44793 // Override and return the set of formats that can be dropped on this view.
794 // |formats| is a bitmask of the formats defined bye OSExchangeData::Format.
795 // The default implementation returns false, which means the view doesn't
796 // support dropping.
797 virtual bool GetDropFormats(
798 int* formats,
799 std::set<OSExchangeData::CustomFormat>* custom_formats);
800
801 // Override and return true if the data must be available before any drop
802 // methods should be invoked. The default is false.
803 virtual bool AreDropTypesRequired();
804
initial.commit09911bf2008-07-26 23:55:29805 // A view that supports drag and drop must override this and return true if
806 // data contains a type that may be dropped on this view.
807 virtual bool CanDrop(const OSExchangeData& data);
808
809 // OnDragEntered is invoked when the mouse enters this view during a drag and
810 // drop session and CanDrop returns true. This is immediately
811 // followed by an invocation of OnDragUpdated, and eventually one of
812 // OnDragExited or OnPerformDrop.
813 virtual void OnDragEntered(const DropTargetEvent& event);
814
815 // Invoked during a drag and drop session while the mouse is over the view.
816 // This should return a bitmask of the DragDropTypes::DragOperation supported
817 // based on the location of the event. Return 0 to indicate the drop should
818 // not be accepted.
819 virtual int OnDragUpdated(const DropTargetEvent& event);
820
821 // Invoked during a drag and drop session when the mouse exits the views, or
822 // when the drag session was canceled and the mouse was over the view.
823 virtual void OnDragExited();
824
825 // Invoked during a drag and drop session when OnDragUpdated returns a valid
826 // operation and the user release the mouse.
827 virtual int OnPerformDrop(const DropTargetEvent& event);
828
829 // Returns true if the mouse was dragged enough to start a drag operation.
830 // delta_x and y are the distance the mouse was dragged.
831 static bool ExceededDragThreshold(int delta_x, int delta_y);
832
833 // This method is the main entry point to process paint for this
834 // view and its children. This method is called by the painting
835 // system. You should call this only if you want to draw a sub tree
836 // inside a custom graphics.
837 // To customize painting override either the Paint or PaintChildren method,
838 // not this one.
[email protected]82522512009-05-15 07:37:29839 virtual void ProcessPaint(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29840
841 // Paint the View's child Views, in reverse order.
[email protected]82522512009-05-15 07:37:29842 virtual void PaintChildren(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29843
844 // Sets the ContextMenuController. Setting this to non-null makes the View
845 // process mouse events.
846 void SetContextMenuController(ContextMenuController* menu_controller);
847 ContextMenuController* GetContextMenuController() {
848 return context_menu_controller_;
849 }
850
[email protected]042811c2008-10-31 21:31:34851 // Provides default implementation for context menu handling. The default
852 // implementation calls the ShowContextMenu of the current
853 // ContextMenuController (if it is not NULL). Overridden in subclassed views
854 // to provide right-click menu display triggerd by the keyboard (i.e. for the
855 // Chrome toolbar Back and Forward buttons). No source needs to be specified,
856 // as it is always equal to the current View.
[email protected]e9adf0702010-03-08 23:34:07857 virtual void ShowContextMenu(const gfx::Point& p,
[email protected]042811c2008-10-31 21:31:34858 bool is_mouse_gesture);
859
[email protected]9a3f0ac22008-11-14 03:24:02860 // The background object is owned by this object and may be NULL.
861 void set_background(Background* b) { background_.reset(b); }
862 const Background* background() const { return background_.get(); }
initial.commit09911bf2008-07-26 23:55:29863
[email protected]9a3f0ac22008-11-14 03:24:02864 // The border object is owned by this object and may be NULL.
865 void set_border(Border* b) { border_.reset(b); }
866 const Border* border() const { return border_.get(); }
initial.commit09911bf2008-07-26 23:55:29867
868 // Returns the insets of the current border. If there is no border an empty
869 // insets is returned.
[email protected]a37bea82009-04-22 23:02:15870 virtual gfx::Insets GetInsets() const;
initial.commit09911bf2008-07-26 23:55:29871
872 // Return the cursor that should be used for this view or NULL if
873 // the default cursor should be used. The provided point is in the
[email protected]9abf8dd62009-06-04 06:40:42874 // receiver's coordinate system. The caller is responsible for managing the
875 // lifetime of the returned object, though that lifetime may vary from
876 // platform to platform. On Windows, the cursor is a shared resource but in
877 // Gtk, the framework destroys the returned cursor after setting it.
878 virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type,
[email protected]e9adf0702010-03-08 23:34:07879 const gfx::Point& p);
initial.commit09911bf2008-07-26 23:55:29880
881 // Convenience to test whether a point is within this view's bounds
[email protected]613b8062008-10-14 23:45:09882 virtual bool HitTest(const gfx::Point& l) const;
initial.commit09911bf2008-07-26 23:55:29883
884 // Gets the tooltip for this View. If the View does not have a tooltip,
885 // return false. If the View does have a tooltip, copy the tooltip into
886 // the supplied string and return true.
887 // Any time the tooltip text that a View is displaying changes, it must
888 // invoke TooltipTextChanged.
[email protected]e9adf0702010-03-08 23:34:07889 // |p| provides the coordinates of the mouse (relative to this view).
890 virtual bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip);
initial.commit09911bf2008-07-26 23:55:29891
892 // Returns the location (relative to this View) for the text on the tooltip
893 // to display. If false is returned (the default), the tooltip is placed at
894 // a default position.
[email protected]e9adf0702010-03-08 23:34:07895 virtual bool GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* loc);
initial.commit09911bf2008-07-26 23:55:29896
897 // Set whether this view is owned by its parent. A view that is owned by its
898 // parent is automatically deleted when the parent is deleted. The default is
899 // true. Set to false if the view is owned by another object and should not
900 // be deleted by its parent.
[email protected]09fe9492009-11-07 02:23:06901 void set_parent_owned(bool is_parent_owned) {
902 is_parent_owned_ = is_parent_owned;
903 }
initial.commit09911bf2008-07-26 23:55:29904
[email protected]09fe9492009-11-07 02:23:06905 // Return whether a view is owned by its parent.
906 bool IsParentOwned() const { return is_parent_owned_; }
initial.commit09911bf2008-07-26 23:55:29907
908 // Return the receiving view's class name. A view class is a string which
909 // uniquely identifies the view class. It is intended to be used as a way to
910 // find out during run time if a view can be safely casted to a specific view
911 // subclass. The default implementation returns kViewClassName.
912 virtual std::string GetClassName() const;
913
[email protected]5c2b98b2009-03-09 20:55:54914 // Returns the first ancestor, starting at this, whose class name is |name|.
915 // Returns null if no ancestor has the class name |name|.
916 View* GetAncestorWithClassName(const std::string& name);
917
initial.commit09911bf2008-07-26 23:55:29918 // Returns the visible bounds of the receiver in the receivers coordinate
919 // system.
920 //
921 // When traversing the View hierarchy in order to compute the bounds, the
922 // function takes into account the mirroring setting for each View and
923 // therefore it will return the mirrored version of the visible bounds if
924 // need be.
925 gfx::Rect GetVisibleBounds();
926
927 // Subclasses that contain traversable children that are not directly
928 // accessible through the children hierarchy should return the associated
929 // FocusTraversable for the focus traversal to work properly.
930 virtual FocusTraversable* GetFocusTraversable() { return NULL; }
931
932#ifndef NDEBUG
933 // Debug method that logs the view hierarchy to the output.
934 void PrintViewHierarchy();
935
936 // Debug method that logs the focus traversal hierarchy to the output.
937 void PrintFocusHierarchy();
938#endif
939
940 // The following methods are used by ScrollView to determine the amount
941 // to scroll relative to the visible bounds of the view. For example, a
942 // return value of 10 indicates the scrollview should scroll 10 pixels in
943 // the appropriate direction.
944 //
945 // Each method takes the following parameters:
946 //
947 // is_horizontal: if true, scrolling is along the horizontal axis, otherwise
948 // the vertical axis.
949 // is_positive: if true, scrolling is by a positive amount. Along the
950 // vertical axis scrolling by a positive amount equates to
951 // scrolling down.
952 //
953 // The return value should always be positive and gives the number of pixels
954 // to scroll. ScrollView interprets a return value of 0 (or negative)
955 // to scroll by a default amount.
956 //
957 // See VariableRowHeightScrollHelper and FixedRowHeightScrollHelper for
958 // implementations of common cases.
959 virtual int GetPageScrollIncrement(ScrollView* scroll_view,
960 bool is_horizontal, bool is_positive);
961 virtual int GetLineScrollIncrement(ScrollView* scroll_view,
962 bool is_horizontal, bool is_positive);
963
[email protected]4a190632009-05-09 01:07:42964 // Get the theme provider from the parent widget.
[email protected]45da6c72009-10-28 20:45:42965 ThemeProvider* GetThemeProvider() const;
[email protected]4a190632009-05-09 01:07:42966
initial.commit09911bf2008-07-26 23:55:29967 protected:
initial.commit09911bf2008-07-26 23:55:29968 // The id of this View. Used to find this View.
969 int id_;
970
971 // The group of this view. Some view subclasses use this id to find other
972 // views of the same group. For example radio button uses this information
973 // to find other radio buttons.
974 int group_;
975
[email protected]32670b02009-03-03 00:28:00976 // Called when the UI theme has changed, overriding allows individual Views to
977 // do special cleanup and processing (such as dropping resource caches).
978 // Subclasses that override this method must call the base class
979 // implementation to ensure child views are processed.
980 // Can only be called by subclasses. To dispatch a theme changed notification,
981 // call this method on the RootView.
982 virtual void ThemeChanged();
983
[email protected]b2b718012010-03-25 15:09:06984 // Called when the locale has changed, overriding allows individual Views to
[email protected]7ceeba72010-04-20 18:22:12985 // update locale-dependent strings.
986 virtual void LocaleChanged() { }
[email protected]b2b718012010-03-25 15:09:06987
initial.commit09911bf2008-07-26 23:55:29988#ifndef NDEBUG
989 // Returns true if the View is currently processing a paint.
990 virtual bool IsProcessingPaint() const;
991#endif
992
[email protected]f704ee72008-11-10 21:31:59993 // Returns the location, in screen coordinates, to show the context menu at
994 // when the context menu is shown from the keyboard. This implementation
995 // returns the middle of the visible region of this view.
996 //
997 // This method is invoked when the context menu is shown by way of the
998 // keyboard.
999 virtual gfx::Point GetKeyboardContextMenuLocation();
1000
[email protected]82739cf2008-09-16 00:37:561001 // Called by HitTest to see if this View has a custom hit test mask. If the
1002 // return value is true, GetHitTestMask will be called to obtain the mask.
1003 // Default value is false, in which case the View will hit-test against its
1004 // bounds.
1005 virtual bool HasHitTestMask() const;
1006
1007 // Called by HitTest to retrieve a mask for hit-testing against. Subclasses
1008 // override to provide custom shaped hit test regions.
1009 virtual void GetHitTestMask(gfx::Path* mask) const;
1010
initial.commit09911bf2008-07-26 23:55:291011 // This method is invoked when the tree changes.
1012 //
1013 // When a view is removed, it is invoked for all children and grand
1014 // children. For each of these views, a notification is sent to the
1015 // view and all parents.
1016 //
1017 // When a view is added, a notification is sent to the view, all its
1018 // parents, and all its children (and grand children)
1019 //
1020 // Default implementation does nothing. Override to perform operations
1021 // required when a view is added or removed from a view hierarchy
1022 //
1023 // parent is the new or old parent. Child is the view being added or
1024 // removed.
1025 //
1026 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
1027
1028 // When SetVisible() changes the visibility of a view, this method is
1029 // invoked for that view as well as all the children recursively.
1030 virtual void VisibilityChanged(View* starting_from, bool is_visible);
1031
[email protected]bda9556c2010-01-07 00:55:161032 // Called when the native view hierarchy changed.
1033 // |attached| is true if that view has been attached to a new NativeView
1034 // hierarchy, false if it has been detached.
1035 // |native_view| is the NativeView this view was attached/detached from, and
1036 // |root_view| is the root view associated with the NativeView.
1037 // Views created without a native view parent don't have a focus manager.
1038 // When this function is called they could do the processing that requires
1039 // it - like registering accelerators, for example.
1040 virtual void NativeViewHierarchyChanged(bool attached,
1041 gfx::NativeView native_view,
1042 RootView* root_view);
1043
[email protected]7ccc52b72009-05-08 21:09:111044 // Called when the preferred size of a child view changed. This gives the
1045 // parent an opportunity to do a fresh layout if that makes sense.
1046 virtual void ChildPreferredSizeChanged(View* child) {}
1047
1048 // Simply calls ChildPreferredSizeChanged on the parent if there is one.
1049 virtual void PreferredSizeChanged();
1050
initial.commit09911bf2008-07-26 23:55:291051 // Views must invoke this when the tooltip text they are to display changes.
1052 void TooltipTextChanged();
1053
initial.commit09911bf2008-07-26 23:55:291054 // Sets whether this view wants notification when its visible bounds relative
1055 // to the root view changes. If true, this view is notified any time the
1056 // origin of one its ancestors changes, or the portion of the bounds not
1057 // obscured by ancestors changes. The default is false.
1058 void SetNotifyWhenVisibleBoundsInRootChanges(bool value);
1059 bool GetNotifyWhenVisibleBoundsInRootChanges();
1060
1061 // Notification that this views visible bounds, relative to the RootView
1062 // has changed. The visible bounds corresponds to the region of the
1063 // view not obscured by other ancestors.
1064 virtual void VisibleBoundsInRootChanged() {}
1065
1066 // Sets the keyboard focus to this View. The correct way to set the focus is
1067 // to call RequestFocus() on the view. This method is called when the focus is
1068 // set and gives an opportunity to subclasses to perform any extra focus steps
1069 // (for example native component set the native focus on their native
1070 // component). The default behavior is to set the native focus on the root
[email protected]a0dde122008-11-21 20:51:201071 // Widget, which is what is appropriate for views that have no native window
1072 // associated with them (so the root view gets the keyboard messages).
initial.commit09911bf2008-07-26 23:55:291073 virtual void Focus();
1074
initial.commit09911bf2008-07-26 23:55:291075 // These are cover methods that invoke the method of the same name on
1076 // the DragController. Subclasses may wish to override rather than install
1077 // a DragController.
1078 // See DragController for a description of these methods.
[email protected]e9adf0702010-03-08 23:34:071079 virtual int GetDragOperations(const gfx::Point& press_pt);
1080 virtual void WriteDragData(const gfx::Point& press_pt, OSExchangeData* data);
initial.commit09911bf2008-07-26 23:55:291081
1082 // Invoked from DoDrag after the drag completes. This implementation does
1083 // nothing, and is intended for subclasses to do cleanup.
1084 virtual void OnDragDone();
1085
1086 // Returns whether we're in the middle of a drag session that was initiated
1087 // by us.
1088 bool InDrag();
1089
[email protected]253a39a2009-05-29 20:45:131090 // Returns how much the mouse needs to move in one direction to start a
1091 // drag. These methods cache in a platform-appropriate way. These values are
1092 // used by the public static method ExceededDragThreshold().
1093 static int GetHorizontalDragThreshold();
1094 static int GetVerticalDragThreshold();
1095
initial.commit09911bf2008-07-26 23:55:291096 // Whether this view is enabled.
1097 bool enabled_;
1098
1099 // Whether the view can be focused.
1100 bool focusable_;
1101
1102 private:
1103 friend class RootView;
1104 friend class FocusManager;
1105 friend class ViewStorage;
1106
1107 // Used to track a drag. RootView passes this into
1108 // ProcessMousePressed/Dragged.
1109 struct DragInfo {
1110 // Sets possible_drag to false and start_x/y to 0. This is invoked by
1111 // RootView prior to invoke ProcessMousePressed.
1112 void Reset();
1113
[email protected]e9adf0702010-03-08 23:34:071114 // Sets possible_drag to true and start_pt to the specified point.
initial.commit09911bf2008-07-26 23:55:291115 // This is invoked by the target view if it detects the press may generate
1116 // a drag.
[email protected]e9adf0702010-03-08 23:34:071117 void PossibleDrag(const gfx::Point& p);
initial.commit09911bf2008-07-26 23:55:291118
1119 // Whether the press may generate a drag.
1120 bool possible_drag;
1121
1122 // Coordinates of the mouse press.
[email protected]e9adf0702010-03-08 23:34:071123 gfx::Point start_pt;
initial.commit09911bf2008-07-26 23:55:291124 };
1125
[email protected]7ceeba72010-04-20 18:22:121126 // Propagates locale changed notification from the root view downside.
1127 // Invokes LocaleChanged() for every view in the hierarchy.
1128 virtual void NotifyLocaleChanged();
1129
initial.commit09911bf2008-07-26 23:55:291130 // RootView invokes these. These in turn invoke the appropriate OnMouseXXX
1131 // method. If a drag is detected, DoDrag is invoked.
1132 bool ProcessMousePressed(const MouseEvent& e, DragInfo* drop_info);
1133 bool ProcessMouseDragged(const MouseEvent& e, DragInfo* drop_info);
1134 void ProcessMouseReleased(const MouseEvent& e, bool canceled);
1135
1136 // Starts a drag and drop operation originating from this view. This invokes
1137 // WriteDragData to write the data and GetDragOperations to determine the
1138 // supported drag operations. When done, OnDragDone is invoked.
[email protected]e9adf0702010-03-08 23:34:071139 void DoDrag(const MouseEvent& e, const gfx::Point& press_pt);
initial.commit09911bf2008-07-26 23:55:291140
initial.commit09911bf2008-07-26 23:55:291141 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true,
1142 // the next and previous focusable views of views pointing to this view are
1143 // updated. If |update_tool_tip| is true, the tooltip is updated. If
1144 // |delete_removed_view| is true, the view is also deleted (if it is parent
1145 // owned).
1146 void DoRemoveChildView(View* view,
1147 bool update_focus_cycle,
1148 bool update_tool_tip,
1149 bool delete_removed_view);
1150
1151 // Sets the parent View. This is called automatically by AddChild and is
1152 // thus private.
[email protected]054e3fd2009-09-14 19:48:051153 void SetParent(View* parent);
initial.commit09911bf2008-07-26 23:55:291154
1155 // Call ViewHierarchyChanged for all child views on all parents
1156 void PropagateRemoveNotifications(View* parent);
1157
1158 // Call ViewHierarchyChanged for all children
1159 void PropagateAddNotifications(View* parent, View* child);
1160
1161 // Call VisibilityChanged() recursively for all children.
1162 void PropagateVisibilityNotifications(View* from, bool is_visible);
1163
[email protected]bda9556c2010-01-07 00:55:161164 // Propagates NativeViewHierarchyChanged() notification through all the
1165 // children.
1166 void PropagateNativeViewHierarchyChanged(bool attached,
1167 gfx::NativeView native_view,
1168 RootView* root_view);
1169
initial.commit09911bf2008-07-26 23:55:291170 // Takes care of registering/unregistering accelerators if
1171 // |register_accelerators| true and calls ViewHierarchyChanged().
1172 void ViewHierarchyChangedImpl(bool register_accelerators,
[email protected]bb515ed2009-01-15 00:53:431173 bool is_add,
1174 View* parent,
1175 View* child);
initial.commit09911bf2008-07-26 23:55:291176
1177 // This is the actual implementation for ConvertPointToView()
1178 // Attempts a parent -> child conversion and then a
1179 // child -> parent conversion if try_other_direction is true
[email protected]bb515ed2009-01-15 00:53:431180 static void ConvertPointToView(const View* src,
1181 const View* dst,
initial.commit09911bf2008-07-26 23:55:291182 gfx::Point* point,
1183 bool try_other_direction);
1184
[email protected]a0dde122008-11-21 20:51:201185 // Propagates UpdateTooltip() to the TooltipManager for the Widget.
initial.commit09911bf2008-07-26 23:55:291186 // This must be invoked any time the View hierarchy changes in such a way
1187 // the view under the mouse differs. For example, if the bounds of a View is
1188 // changed, this is invoked. Similarly, as Views are added/removed, this
1189 // is invoked.
1190 void UpdateTooltip();
1191
1192 // Recursively descends through all descendant views,
1193 // registering/unregistering all views that want visible bounds in root
1194 // view notification.
1195 static void RegisterChildrenForVisibleBoundsNotification(RootView* root,
1196 View* view);
1197 static void UnregisterChildrenForVisibleBoundsNotification(RootView* root,
1198 View* view);
1199
1200 // Adds/removes view to the list of descendants that are notified any time
1201 // this views location and possibly size are changed.
1202 void AddDescendantToNotify(View* view);
1203 void RemoveDescendantToNotify(View* view);
1204
1205 // Initialize the previous/next focusable views of the specified view relative
1206 // to the view at the specified index.
1207 void InitFocusSiblings(View* view, int index);
1208
1209 // Actual implementation of PrintFocusHierarchy.
1210 void PrintViewHierarchyImp(int indent);
1211 void PrintFocusHierarchyImp(int indent);
1212
[email protected]71421c3f2009-06-06 00:41:441213 // Registers this view's keyboard accelerators that are not registered to
1214 // FocusManager yet, if possible.
1215 void RegisterPendingAccelerators();
1216
1217 // Unregisters all the keyboard accelerators associated with this view.
[email protected]bda9556c2010-01-07 00:55:161218 // |leave_data_intact| if true does not remove data from accelerators_ array,
1219 // so it could be re-registered with other focus manager
1220 void UnregisterAccelerators(bool leave_data_intact);
initial.commit09911bf2008-07-26 23:55:291221
[email protected]80f8b9f2008-10-16 18:17:471222 // This View's bounds in the parent coordinate system.
1223 gfx::Rect bounds_;
1224
initial.commit09911bf2008-07-26 23:55:291225 // This view's parent
[email protected]054e3fd2009-09-14 19:48:051226 View* parent_;
initial.commit09911bf2008-07-26 23:55:291227
1228 // This view's children.
1229 typedef std::vector<View*> ViewList;
1230 ViewList child_views_;
1231
initial.commit09911bf2008-07-26 23:55:291232 // The View's LayoutManager defines the sizing heuristics applied to child
1233 // Views. The default is absolute positioning according to bounds_.
1234 scoped_ptr<LayoutManager> layout_manager_;
1235
1236 // Visible state
1237 bool is_visible_;
1238
1239 // Background
[email protected]9a3f0ac22008-11-14 03:24:021240 scoped_ptr<Background> background_;
initial.commit09911bf2008-07-26 23:55:291241
1242 // Border.
[email protected]9a3f0ac22008-11-14 03:24:021243 scoped_ptr<Border> border_;
initial.commit09911bf2008-07-26 23:55:291244
1245 // Whether this view is owned by its parent.
1246 bool is_parent_owned_;
1247
1248 // See SetNotifyWhenVisibleBoundsInRootChanges.
1249 bool notify_when_visible_bounds_in_root_changes_;
1250
1251 // Whether or not RegisterViewForVisibleBoundsNotification on the RootView
1252 // has been invoked.
1253 bool registered_for_visible_bounds_notification_;
1254
[email protected]bda9556c2010-01-07 00:55:161255 // true if when we were added to hierarchy we were without focus manager
1256 // attempt addition when ancestor chain changed.
1257 bool accelerator_registration_delayed_;
1258
initial.commit09911bf2008-07-26 23:55:291259 // List of descendants wanting notification when their visible bounds change.
1260 scoped_ptr<ViewList> descendants_to_notify_;
1261
[email protected]d5c81012010-04-03 00:56:121262 // Name for this view, which can be retrieved by accessibility APIs.
1263 std::wstring accessible_name_;
1264
initial.commit09911bf2008-07-26 23:55:291265 // Next view to be focused when the Tab key is pressed.
1266 View* next_focusable_view_;
1267
1268 // Next view to be focused when the Shift-Tab key combination is pressed.
1269 View* previous_focusable_view_;
1270
[email protected]bda9556c2010-01-07 00:55:161271 // Focus manager accelerators registered on.
1272 FocusManager* accelerator_focus_manager_;
1273
[email protected]71421c3f2009-06-06 00:41:441274 // The list of accelerators. List elements in the range
1275 // [0, registered_accelerator_count_) are already registered to FocusManager,
1276 // and the rest are not yet.
[email protected]1eb89e82008-08-15 12:27:031277 scoped_ptr<std::vector<Accelerator> > accelerators_;
[email protected]4bd23f32009-06-08 20:59:191278 size_t registered_accelerator_count_;
initial.commit09911bf2008-07-26 23:55:291279
initial.commit09911bf2008-07-26 23:55:291280 // The menu controller.
1281 ContextMenuController* context_menu_controller_;
1282
[email protected]6ff244f2009-01-20 20:38:081283#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291284 // The accessibility implementation for this View.
[email protected]fef10642009-03-17 21:17:041285 scoped_ptr<ViewAccessibilityWrapper> accessibility_;
[email protected]6ff244f2009-01-20 20:38:081286#endif
initial.commit09911bf2008-07-26 23:55:291287
1288 DragController* drag_controller_;
1289
1290 // Indicates whether or not the view is going to be mirrored (that is, use a
1291 // right-to-left UI layout) if the locale's language is a right-to-left
1292 // language like Arabic or Hebrew.
1293 bool ui_mirroring_is_enabled_for_rtl_languages_;
1294
[email protected]82522512009-05-15 07:37:291295 // Indicates whether or not the gfx::Canvas object passed to View::Paint()
initial.commit09911bf2008-07-26 23:55:291296 // is going to be flipped horizontally (using the appropriate transform) on
1297 // right-to-left locales for this View.
1298 bool flip_canvas_on_paint_for_rtl_ui_;
1299
[email protected]8af4c1992010-02-04 21:38:071300 // The default value for how long to wait (in ms) before showing a menu
1301 // button on hover. This value is used if the OS doesn't supply one.
1302 static const int kShowFolderDropMenuDelay;
1303
[email protected]1eb89e82008-08-15 12:27:031304 DISALLOW_COPY_AND_ASSIGN(View);
initial.commit09911bf2008-07-26 23:55:291305};
1306
[email protected]c2dacc92008-10-16 23:51:381307} // namespace views
initial.commit09911bf2008-07-26 23:55:291308
[email protected]2362e4f2009-05-08 00:34:051309#endif // VIEWS_VIEW_H_