Dispatch scroll events in views using EventProcessor and EventTargeter
[chromium-blink-merge.git] / ui / views / view.h
blob027e212d7c47faa1878806eb40dacc2ed7828515
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_VIEW_H_
6 #define UI_VIEWS_VIEW_H_
8 #include <algorithm>
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <vector>
14 #include "base/compiler_specific.h"
15 #include "base/i18n/rtl.h"
16 #include "base/logging.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "build/build_config.h"
19 #include "ui/accessibility/ax_enums.h"
20 #include "ui/base/accelerators/accelerator.h"
21 #include "ui/base/dragdrop/drag_drop_types.h"
22 #include "ui/base/dragdrop/drop_target_event.h"
23 #include "ui/base/dragdrop/os_exchange_data.h"
24 #include "ui/base/ui_base_types.h"
25 #include "ui/compositor/layer_delegate.h"
26 #include "ui/compositor/layer_owner.h"
27 #include "ui/events/event.h"
28 #include "ui/events/event_target.h"
29 #include "ui/events/event_targeter.h"
30 #include "ui/gfx/insets.h"
31 #include "ui/gfx/native_widget_types.h"
32 #include "ui/gfx/rect.h"
33 #include "ui/gfx/vector2d.h"
34 #include "ui/views/views_export.h"
36 #if defined(OS_WIN)
37 #include "base/win/scoped_comptr.h"
38 #endif
40 using ui::OSExchangeData;
42 namespace gfx {
43 class Canvas;
44 class Insets;
45 class Path;
46 class Transform;
49 namespace ui {
50 struct AXViewState;
51 class Compositor;
52 class Layer;
53 class NativeTheme;
54 class TextInputClient;
55 class Texture;
56 class ThemeProvider;
59 namespace views {
61 class Background;
62 class Border;
63 class ContextMenuController;
64 class DragController;
65 class FocusManager;
66 class FocusTraversable;
67 class InputMethod;
68 class LayoutManager;
69 class NativeViewAccessibility;
70 class ScrollView;
71 class Widget;
73 namespace internal {
74 class PreEventDispatchHandler;
75 class PostEventDispatchHandler;
76 class RootView;
79 /////////////////////////////////////////////////////////////////////////////
81 // View class
83 // A View is a rectangle within the views View hierarchy. It is the base
84 // class for all Views.
86 // A View is a container of other Views (there is no such thing as a Leaf
87 // View - makes code simpler, reduces type conversion headaches, design
88 // mistakes etc)
90 // The View contains basic properties for sizing (bounds), layout (flex,
91 // orientation, etc), painting of children and event dispatch.
93 // The View also uses a simple Box Layout Manager similar to XUL's
94 // SprocketLayout system. Alternative Layout Managers implementing the
95 // LayoutManager interface can be used to lay out children if required.
97 // It is up to the subclass to implement Painting and storage of subclass -
98 // specific properties and functionality.
100 // Unless otherwise documented, views is not thread safe and should only be
101 // accessed from the main thread.
103 /////////////////////////////////////////////////////////////////////////////
104 class VIEWS_EXPORT View : public ui::LayerDelegate,
105 public ui::LayerOwner,
106 public ui::AcceleratorTarget,
107 public ui::EventTarget {
108 public:
109 typedef std::vector<View*> Views;
111 // TODO(tdanderson): Becomes obsolete with the refactoring of the event
112 // targeting logic for views and windows. See
113 // crbug.com/355425.
114 // Specifies the source of the region used in a hit test.
115 // HIT_TEST_SOURCE_MOUSE indicates the hit test is being performed with a
116 // single point and HIT_TEST_SOURCE_TOUCH indicates the hit test is being
117 // performed with a rect larger than a single point. This value can be used,
118 // for example, to add extra padding or change the shape of the hit test mask.
119 enum HitTestSource {
120 HIT_TEST_SOURCE_MOUSE,
121 HIT_TEST_SOURCE_TOUCH
124 struct ViewHierarchyChangedDetails {
125 ViewHierarchyChangedDetails()
126 : is_add(false),
127 parent(NULL),
128 child(NULL),
129 move_view(NULL) {}
131 ViewHierarchyChangedDetails(bool is_add,
132 View* parent,
133 View* child,
134 View* move_view)
135 : is_add(is_add),
136 parent(parent),
137 child(child),
138 move_view(move_view) {}
140 bool is_add;
141 // New parent if |is_add| is true, old parent if |is_add| is false.
142 View* parent;
143 // The view being added or removed.
144 View* child;
145 // If this is a move (reparent), meaning AddChildViewAt() is invoked with an
146 // existing parent, then a notification for the remove is sent first,
147 // followed by one for the add. This case can be distinguished by a
148 // non-NULL |move_view|.
149 // For the remove part of move, |move_view| is the new parent of the View
150 // being removed.
151 // For the add part of move, |move_view| is the old parent of the View being
152 // added.
153 View* move_view;
156 // Creation and lifetime -----------------------------------------------------
158 View();
159 virtual ~View();
161 // By default a View is owned by its parent unless specified otherwise here.
162 void set_owned_by_client() { owned_by_client_ = true; }
164 // Tree operations -----------------------------------------------------------
166 // Get the Widget that hosts this View, if any.
167 virtual const Widget* GetWidget() const;
168 virtual Widget* GetWidget();
170 // Adds |view| as a child of this view, optionally at |index|.
171 void AddChildView(View* view);
172 void AddChildViewAt(View* view, int index);
174 // Moves |view| to the specified |index|. A negative value for |index| moves
175 // the view at the end.
176 void ReorderChildView(View* view, int index);
178 // Removes |view| from this view. The view's parent will change to NULL.
179 void RemoveChildView(View* view);
181 // Removes all the children from this view. If |delete_children| is true,
182 // the views are deleted, unless marked as not parent owned.
183 void RemoveAllChildViews(bool delete_children);
185 int child_count() const { return static_cast<int>(children_.size()); }
186 bool has_children() const { return !children_.empty(); }
188 // Returns the child view at |index|.
189 const View* child_at(int index) const {
190 DCHECK_GE(index, 0);
191 DCHECK_LT(index, child_count());
192 return children_[index];
194 View* child_at(int index) {
195 return const_cast<View*>(const_cast<const View*>(this)->child_at(index));
198 // Returns the parent view.
199 const View* parent() const { return parent_; }
200 View* parent() { return parent_; }
202 // Returns true if |view| is contained within this View's hierarchy, even as
203 // an indirect descendant. Will return true if child is also this view.
204 bool Contains(const View* view) const;
206 // Returns the index of |view|, or -1 if |view| is not a child of this view.
207 int GetIndexOf(const View* view) const;
209 // Size and disposition ------------------------------------------------------
210 // Methods for obtaining and modifying the position and size of the view.
211 // Position is in the coordinate system of the view's parent.
212 // Position is NOT flipped for RTL. See "RTL positioning" for RTL-sensitive
213 // position accessors.
214 // Transformations are not applied on the size/position. For example, if
215 // bounds is (0, 0, 100, 100) and it is scaled by 0.5 along the X axis, the
216 // width will still be 100 (although when painted, it will be 50x50, painted
217 // at location (0, 0)).
219 void SetBounds(int x, int y, int width, int height);
220 void SetBoundsRect(const gfx::Rect& bounds);
221 void SetSize(const gfx::Size& size);
222 void SetPosition(const gfx::Point& position);
223 void SetX(int x);
224 void SetY(int y);
226 // No transformation is applied on the size or the locations.
227 const gfx::Rect& bounds() const { return bounds_; }
228 int x() const { return bounds_.x(); }
229 int y() const { return bounds_.y(); }
230 int width() const { return bounds_.width(); }
231 int height() const { return bounds_.height(); }
232 const gfx::Size& size() const { return bounds_.size(); }
234 // Returns the bounds of the content area of the view, i.e. the rectangle
235 // enclosed by the view's border.
236 gfx::Rect GetContentsBounds() const;
238 // Returns the bounds of the view in its own coordinates (i.e. position is
239 // 0, 0).
240 gfx::Rect GetLocalBounds() const;
242 // Returns the bounds of the layer in its own pixel coordinates.
243 gfx::Rect GetLayerBoundsInPixel() const;
245 // Returns the insets of the current border. If there is no border an empty
246 // insets is returned.
247 virtual gfx::Insets GetInsets() const;
249 // Returns the visible bounds of the receiver in the receivers coordinate
250 // system.
252 // When traversing the View hierarchy in order to compute the bounds, the
253 // function takes into account the mirroring setting and transformation for
254 // each View and therefore it will return the mirrored and transformed version
255 // of the visible bounds if need be.
256 gfx::Rect GetVisibleBounds() const;
258 // Return the bounds of the View in screen coordinate system.
259 gfx::Rect GetBoundsInScreen() const;
261 // Returns the baseline of this view, or -1 if this view has no baseline. The
262 // return value is relative to the preferred height.
263 virtual int GetBaseline() const;
265 // Get the size the View would like to be, if enough space were available.
266 virtual gfx::Size GetPreferredSize();
268 // Convenience method that sizes this view to its preferred size.
269 void SizeToPreferredSize();
271 // Gets the minimum size of the view. View's implementation invokes
272 // GetPreferredSize.
273 virtual gfx::Size GetMinimumSize();
275 // Gets the maximum size of the view. Currently only used for sizing shell
276 // windows.
277 virtual gfx::Size GetMaximumSize();
279 // Return the height necessary to display this view with the provided width.
280 // View's implementation returns the value from getPreferredSize.cy.
281 // Override if your View's preferred height depends upon the width (such
282 // as with Labels).
283 virtual int GetHeightForWidth(int w);
285 // Set whether this view is visible. Painting is scheduled as needed.
286 virtual void SetVisible(bool visible);
288 // Return whether a view is visible
289 bool visible() const { return visible_; }
291 // Returns true if this view is drawn on screen.
292 virtual bool IsDrawn() const;
294 // Set whether this view is enabled. A disabled view does not receive keyboard
295 // or mouse inputs. If |enabled| differs from the current value, SchedulePaint
296 // is invoked.
297 void SetEnabled(bool enabled);
299 // Returns whether the view is enabled.
300 bool enabled() const { return enabled_; }
302 // This indicates that the view completely fills its bounds in an opaque
303 // color. This doesn't affect compositing but is a hint to the compositor to
304 // optimize painting.
305 // Note that this method does not implicitly create a layer if one does not
306 // already exist for the View, but is a no-op in that case.
307 void SetFillsBoundsOpaquely(bool fills_bounds_opaquely);
309 // Transformations -----------------------------------------------------------
311 // Methods for setting transformations for a view (e.g. rotation, scaling).
313 gfx::Transform GetTransform() const;
315 // Clipping parameters. Clipping is done relative to the view bounds.
316 void set_clip_insets(gfx::Insets clip_insets) { clip_insets_ = clip_insets; }
318 // Sets the transform to the supplied transform.
319 void SetTransform(const gfx::Transform& transform);
321 // Sets whether this view paints to a layer. A view paints to a layer if
322 // either of the following are true:
323 // . the view has a non-identity transform.
324 // . SetPaintToLayer(true) has been invoked.
325 // View creates the Layer only when it exists in a Widget with a non-NULL
326 // Compositor.
327 void SetPaintToLayer(bool paint_to_layer);
329 // RTL positioning -----------------------------------------------------------
331 // Methods for accessing the bounds and position of the view, relative to its
332 // parent. The position returned is mirrored if the parent view is using a RTL
333 // layout.
335 // NOTE: in the vast majority of the cases, the mirroring implementation is
336 // transparent to the View subclasses and therefore you should use the
337 // bounds() accessor instead.
338 gfx::Rect GetMirroredBounds() const;
339 gfx::Point GetMirroredPosition() const;
340 int GetMirroredX() const;
342 // Given a rectangle specified in this View's coordinate system, the function
343 // computes the 'left' value for the mirrored rectangle within this View. If
344 // the View's UI layout is not right-to-left, then bounds.x() is returned.
346 // UI mirroring is transparent to most View subclasses and therefore there is
347 // no need to call this routine from anywhere within your subclass
348 // implementation.
349 int GetMirroredXForRect(const gfx::Rect& rect) const;
351 // Given the X coordinate of a point inside the View, this function returns
352 // the mirrored X coordinate of the point if the View's UI layout is
353 // right-to-left. If the layout is left-to-right, the same X coordinate is
354 // returned.
356 // Following are a few examples of the values returned by this function for
357 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout:
359 // GetMirroredXCoordinateInView(0) -> 100
360 // GetMirroredXCoordinateInView(20) -> 80
361 // GetMirroredXCoordinateInView(99) -> 1
362 int GetMirroredXInView(int x) const;
364 // Given a X coordinate and a width inside the View, this function returns
365 // the mirrored X coordinate if the View's UI layout is right-to-left. If the
366 // layout is left-to-right, the same X coordinate is returned.
368 // Following are a few examples of the values returned by this function for
369 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout:
371 // GetMirroredXCoordinateInView(0, 10) -> 90
372 // GetMirroredXCoordinateInView(20, 20) -> 60
373 int GetMirroredXWithWidthInView(int x, int w) const;
375 // Layout --------------------------------------------------------------------
377 // Lay out the child Views (set their bounds based on sizing heuristics
378 // specific to the current Layout Manager)
379 virtual void Layout();
381 // TODO(beng): I think we should remove this.
382 // Mark this view and all parents to require a relayout. This ensures the
383 // next call to Layout() will propagate to this view, even if the bounds of
384 // parent views do not change.
385 void InvalidateLayout();
387 // Gets/Sets the Layout Manager used by this view to size and place its
388 // children.
389 // The LayoutManager is owned by the View and is deleted when the view is
390 // deleted, or when a new LayoutManager is installed.
391 LayoutManager* GetLayoutManager() const;
392 void SetLayoutManager(LayoutManager* layout);
394 // Attributes ----------------------------------------------------------------
396 // The view class name.
397 static const char kViewClassName[];
399 // Return the receiving view's class name. A view class is a string which
400 // uniquely identifies the view class. It is intended to be used as a way to
401 // find out during run time if a view can be safely casted to a specific view
402 // subclass. The default implementation returns kViewClassName.
403 virtual const char* GetClassName() const;
405 // Returns the first ancestor, starting at this, whose class name is |name|.
406 // Returns null if no ancestor has the class name |name|.
407 const View* GetAncestorWithClassName(const std::string& name) const;
408 View* GetAncestorWithClassName(const std::string& name);
410 // Recursively descends the view tree starting at this view, and returns
411 // the first child that it encounters that has the given ID.
412 // Returns NULL if no matching child view is found.
413 virtual const View* GetViewByID(int id) const;
414 virtual View* GetViewByID(int id);
416 // Gets and sets the ID for this view. ID should be unique within the subtree
417 // that you intend to search for it. 0 is the default ID for views.
418 int id() const { return id_; }
419 void set_id(int id) { id_ = id; }
421 // A group id is used to tag views which are part of the same logical group.
422 // Focus can be moved between views with the same group using the arrow keys.
423 // Groups are currently used to implement radio button mutual exclusion.
424 // The group id is immutable once it's set.
425 void SetGroup(int gid);
426 // Returns the group id of the view, or -1 if the id is not set yet.
427 int GetGroup() const;
429 // If this returns true, the views from the same group can each be focused
430 // when moving focus with the Tab/Shift-Tab key. If this returns false,
431 // only the selected view from the group (obtained with
432 // GetSelectedViewForGroup()) is focused.
433 virtual bool IsGroupFocusTraversable() const;
435 // Fills |views| with all the available views which belong to the provided
436 // |group|.
437 void GetViewsInGroup(int group, Views* views);
439 // Returns the View that is currently selected in |group|.
440 // The default implementation simply returns the first View found for that
441 // group.
442 virtual View* GetSelectedViewForGroup(int group);
444 // Coordinate conversion -----------------------------------------------------
446 // Note that the utility coordinate conversions functions always operate on
447 // the mirrored position of the child Views if the parent View uses a
448 // right-to-left UI layout.
450 // Convert a point from the coordinate system of one View to another.
452 // |source| and |target| must be in the same widget, but doesn't need to be in
453 // the same view hierarchy.
454 // Neither |source| nor |target| can be NULL.
455 static void ConvertPointToTarget(const View* source,
456 const View* target,
457 gfx::Point* point);
459 // Convert |rect| from the coordinate system of |source| to the coordinate
460 // system of |target|.
462 // |source| and |target| must be in the same widget, but doesn't need to be in
463 // the same view hierarchy.
464 // Neither |source| nor |target| can be NULL.
465 static void ConvertRectToTarget(const View* source,
466 const View* target,
467 gfx::RectF* rect);
469 // Convert a point from a View's coordinate system to that of its Widget.
470 static void ConvertPointToWidget(const View* src, gfx::Point* point);
472 // Convert a point from the coordinate system of a View's Widget to that
473 // View's coordinate system.
474 static void ConvertPointFromWidget(const View* dest, gfx::Point* p);
476 // Convert a point from a View's coordinate system to that of the screen.
477 static void ConvertPointToScreen(const View* src, gfx::Point* point);
479 // Convert a point from a View's coordinate system to that of the screen.
480 static void ConvertPointFromScreen(const View* dst, gfx::Point* point);
482 // Applies transformation on the rectangle, which is in the view's coordinate
483 // system, to convert it into the parent's coordinate system.
484 gfx::Rect ConvertRectToParent(const gfx::Rect& rect) const;
486 // Converts a rectangle from this views coordinate system to its widget
487 // coordinate system.
488 gfx::Rect ConvertRectToWidget(const gfx::Rect& rect) const;
490 // Painting ------------------------------------------------------------------
492 // Mark all or part of the View's bounds as dirty (needing repaint).
493 // |r| is in the View's coordinates.
494 // Rectangle |r| should be in the view's coordinate system. The
495 // transformations are applied to it to convert it into the parent coordinate
496 // system before propagating SchedulePaint up the view hierarchy.
497 // TODO(beng): Make protected.
498 virtual void SchedulePaint();
499 virtual void SchedulePaintInRect(const gfx::Rect& r);
501 // Called by the framework to paint a View. Performs translation and clipping
502 // for View coordinates and language direction as required, allows the View
503 // to paint itself via the various OnPaint*() event handlers and then paints
504 // the hierarchy beneath it.
505 virtual void Paint(gfx::Canvas* canvas);
507 // The background object is owned by this object and may be NULL.
508 void set_background(Background* b);
509 const Background* background() const { return background_.get(); }
510 Background* background() { return background_.get(); }
512 // The border object is owned by this object and may be NULL.
513 virtual void SetBorder(scoped_ptr<Border> b);
514 const Border* border() const { return border_.get(); }
515 Border* border() { return border_.get(); }
517 // Get the theme provider from the parent widget.
518 ui::ThemeProvider* GetThemeProvider() const;
520 // Returns the NativeTheme to use for this View. This calls through to
521 // GetNativeTheme() on the Widget this View is in. If this View is not in a
522 // Widget this returns ui::NativeTheme::instance().
523 ui::NativeTheme* GetNativeTheme() {
524 return const_cast<ui::NativeTheme*>(
525 const_cast<const View*>(this)->GetNativeTheme());
527 const ui::NativeTheme* GetNativeTheme() const;
529 // RTL painting --------------------------------------------------------------
531 // This method determines whether the gfx::Canvas object passed to
532 // View::Paint() needs to be transformed such that anything drawn on the
533 // canvas object during View::Paint() is flipped horizontally.
535 // By default, this function returns false (which is the initial value of
536 // |flip_canvas_on_paint_for_rtl_ui_|). View subclasses that need to paint on
537 // a flipped gfx::Canvas when the UI layout is right-to-left need to call
538 // EnableCanvasFlippingForRTLUI().
539 bool FlipCanvasOnPaintForRTLUI() const {
540 return flip_canvas_on_paint_for_rtl_ui_ ? base::i18n::IsRTL() : false;
543 // Enables or disables flipping of the gfx::Canvas during View::Paint().
544 // Note that if canvas flipping is enabled, the canvas will be flipped only
545 // if the UI layout is right-to-left; that is, the canvas will be flipped
546 // only if base::i18n::IsRTL() returns true.
548 // Enabling canvas flipping is useful for leaf views that draw an image that
549 // needs to be flipped horizontally when the UI layout is right-to-left
550 // (views::Button, for example). This method is helpful for such classes
551 // because their drawing logic stays the same and they can become agnostic to
552 // the UI directionality.
553 void EnableCanvasFlippingForRTLUI(bool enable) {
554 flip_canvas_on_paint_for_rtl_ui_ = enable;
557 // Input ---------------------------------------------------------------------
558 // The points, rects, mouse locations, and touch locations in the following
559 // functions are in the view's coordinates, except for a RootView.
561 // TODO(tdanderson): GetEventHandlerForPoint() and GetEventHandlerForRect()
562 // will be removed once their logic is moved into
563 // ViewTargeter and its derived classes. See
564 // crbug.com/355425.
566 // Convenience functions which calls into GetEventHandler() with
567 // a 1x1 rect centered at |point|.
568 View* GetEventHandlerForPoint(const gfx::Point& point);
570 // If point-based targeting should be used, return the deepest visible
571 // descendant that contains the center point of |rect|.
572 // If rect-based targeting (i.e., fuzzing) should be used, return the
573 // closest visible descendant having at least kRectTargetOverlap of
574 // its area covered by |rect|. If no such descendant exists, return the
575 // deepest visible descendant that contains the center point of |rect|.
576 // See http://goo.gl/3Jp2BD for more information about rect-based targeting.
577 virtual View* GetEventHandlerForRect(const gfx::Rect& rect);
579 // Returns the deepest visible descendant that contains the specified point
580 // and supports tooltips. If the view does not contain the point, returns
581 // NULL.
582 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point);
584 // Return the cursor that should be used for this view or the default cursor.
585 // The event location is in the receiver's coordinate system. The caller is
586 // responsible for managing the lifetime of the returned object, though that
587 // lifetime may vary from platform to platform. On Windows and Aura,
588 // the cursor is a shared resource.
589 virtual gfx::NativeCursor GetCursor(const ui::MouseEvent& event);
591 // TODO(tdanderson): HitTestPoint() and HitTestRect() will be removed once
592 // their logic is moved into ViewTargeter and its
593 // derived classes. See crbug.com/355425.
595 // A convenience function which calls HitTestRect() with a rect of size
596 // 1x1 and an origin of |point|.
597 bool HitTestPoint(const gfx::Point& point) const;
599 // Tests whether |rect| intersects this view's bounds.
600 virtual bool HitTestRect(const gfx::Rect& rect) const;
602 // Returns true if the mouse cursor is over |view| and mouse events are
603 // enabled.
604 bool IsMouseHovered();
606 // This method is invoked when the user clicks on this view.
607 // The provided event is in the receiver's coordinate system.
609 // Return true if you processed the event and want to receive subsequent
610 // MouseDraggged and MouseReleased events. This also stops the event from
611 // bubbling. If you return false, the event will bubble through parent
612 // views.
614 // If you remove yourself from the tree while processing this, event bubbling
615 // stops as if you returned true, but you will not receive future events.
616 // The return value is ignored in this case.
618 // Default implementation returns true if a ContextMenuController has been
619 // set, false otherwise. Override as needed.
621 virtual bool OnMousePressed(const ui::MouseEvent& event);
623 // This method is invoked when the user clicked on this control.
624 // and is still moving the mouse with a button pressed.
625 // The provided event is in the receiver's coordinate system.
627 // Return true if you processed the event and want to receive
628 // subsequent MouseDragged and MouseReleased events.
630 // Default implementation returns true if a ContextMenuController has been
631 // set, false otherwise. Override as needed.
633 virtual bool OnMouseDragged(const ui::MouseEvent& event);
635 // This method is invoked when the user releases the mouse
636 // button. The event is in the receiver's coordinate system.
638 // Default implementation notifies the ContextMenuController is appropriate.
639 // Subclasses that wish to honor the ContextMenuController should invoke
640 // super.
641 virtual void OnMouseReleased(const ui::MouseEvent& event);
643 // This method is invoked when the mouse press/drag was canceled by a
644 // system/user gesture.
645 virtual void OnMouseCaptureLost();
647 // This method is invoked when the mouse is above this control
648 // The event is in the receiver's coordinate system.
650 // Default implementation does nothing. Override as needed.
651 virtual void OnMouseMoved(const ui::MouseEvent& event);
653 // This method is invoked when the mouse enters this control.
655 // Default implementation does nothing. Override as needed.
656 virtual void OnMouseEntered(const ui::MouseEvent& event);
658 // This method is invoked when the mouse exits this control
659 // The provided event location is always (0, 0)
660 // Default implementation does nothing. Override as needed.
661 virtual void OnMouseExited(const ui::MouseEvent& event);
663 // Set the MouseHandler for a drag session.
665 // A drag session is a stream of mouse events starting
666 // with a MousePressed event, followed by several MouseDragged
667 // events and finishing with a MouseReleased event.
669 // This method should be only invoked while processing a
670 // MouseDragged or MousePressed event.
672 // All further mouse dragged and mouse up events will be sent
673 // the MouseHandler, even if it is reparented to another window.
675 // The MouseHandler is automatically cleared when the control
676 // comes back from processing the MouseReleased event.
678 // Note: if the mouse handler is no longer connected to a
679 // view hierarchy, events won't be sent.
681 // TODO(sky): rename this.
682 virtual void SetMouseHandler(View* new_mouse_handler);
684 // Invoked when a key is pressed or released.
685 // Subclasser should return true if the event has been processed and false
686 // otherwise. If the event has not been processed, the parent will be given a
687 // chance.
688 virtual bool OnKeyPressed(const ui::KeyEvent& event);
689 virtual bool OnKeyReleased(const ui::KeyEvent& event);
691 // Invoked when the user uses the mousewheel. Implementors should return true
692 // if the event has been processed and false otherwise. This message is sent
693 // if the view is focused. If the event has not been processed, the parent
694 // will be given a chance.
695 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event);
698 // See field for description.
699 void set_notify_enter_exit_on_child(bool notify) {
700 notify_enter_exit_on_child_ = notify;
702 bool notify_enter_exit_on_child() const {
703 return notify_enter_exit_on_child_;
706 // Returns the View's TextInputClient instance or NULL if the View doesn't
707 // support text input.
708 virtual ui::TextInputClient* GetTextInputClient();
710 // Convenience method to retrieve the InputMethod associated with the
711 // Widget that contains this view. Returns NULL if this view is not part of a
712 // view hierarchy with a Widget.
713 virtual InputMethod* GetInputMethod();
714 virtual const InputMethod* GetInputMethod() const;
716 // Sets a new event-targeter for the view, and returns the previous
717 // event-targeter.
718 scoped_ptr<ui::EventTargeter> SetEventTargeter(
719 scoped_ptr<ui::EventTargeter> targeter);
721 // Overridden from ui::EventTarget:
722 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
723 virtual ui::EventTarget* GetParentTarget() OVERRIDE;
724 virtual scoped_ptr<ui::EventTargetIterator> GetChildIterator() const OVERRIDE;
725 virtual ui::EventTargeter* GetEventTargeter() OVERRIDE;
726 virtual void ConvertEventToTarget(ui::EventTarget* target,
727 ui::LocatedEvent* event) OVERRIDE;
729 // Overridden from ui::EventHandler:
730 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
731 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
732 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
733 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE FINAL;
734 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
736 // Accelerators --------------------------------------------------------------
738 // Sets a keyboard accelerator for that view. When the user presses the
739 // accelerator key combination, the AcceleratorPressed method is invoked.
740 // Note that you can set multiple accelerators for a view by invoking this
741 // method several times. Note also that AcceleratorPressed is invoked only
742 // when CanHandleAccelerators() is true.
743 virtual void AddAccelerator(const ui::Accelerator& accelerator);
745 // Removes the specified accelerator for this view.
746 virtual void RemoveAccelerator(const ui::Accelerator& accelerator);
748 // Removes all the keyboard accelerators for this view.
749 virtual void ResetAccelerators();
751 // Overridden from AcceleratorTarget:
752 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
754 // Returns whether accelerators are enabled for this view. Accelerators are
755 // enabled if the containing widget is visible and the view is enabled() and
756 // IsDrawn()
757 virtual bool CanHandleAccelerators() const OVERRIDE;
759 // Focus ---------------------------------------------------------------------
761 // Returns whether this view currently has the focus.
762 virtual bool HasFocus() const;
764 // Returns the view that should be selected next when pressing Tab.
765 View* GetNextFocusableView();
766 const View* GetNextFocusableView() const;
768 // Returns the view that should be selected next when pressing Shift-Tab.
769 View* GetPreviousFocusableView();
771 // Sets the component that should be selected next when pressing Tab, and
772 // makes the current view the precedent view of the specified one.
773 // Note that by default views are linked in the order they have been added to
774 // their container. Use this method if you want to modify the order.
775 // IMPORTANT NOTE: loops in the focus hierarchy are not supported.
776 void SetNextFocusableView(View* view);
778 // Sets whether this view is capable of taking focus.
779 // Note that this is false by default so that a view used as a container does
780 // not get the focus.
781 void SetFocusable(bool focusable);
783 // Returns true if this view is |focusable_|, |enabled_| and drawn.
784 virtual bool IsFocusable() const;
786 // Return whether this view is focusable when the user requires full keyboard
787 // access, even though it may not be normally focusable.
788 bool IsAccessibilityFocusable() const;
790 // Set whether this view can be made focusable if the user requires
791 // full keyboard access, even though it's not normally focusable.
792 // Note that this is false by default.
793 void SetAccessibilityFocusable(bool accessibility_focusable);
795 // Convenience method to retrieve the FocusManager associated with the
796 // Widget that contains this view. This can return NULL if this view is not
797 // part of a view hierarchy with a Widget.
798 virtual FocusManager* GetFocusManager();
799 virtual const FocusManager* GetFocusManager() const;
801 // Request keyboard focus. The receiving view will become the focused view.
802 virtual void RequestFocus();
804 // Invoked when a view is about to be requested for focus due to the focus
805 // traversal. Reverse is this request was generated going backward
806 // (Shift-Tab).
807 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) {}
809 // Invoked when a key is pressed before the key event is processed (and
810 // potentially eaten) by the focus manager for tab traversal, accelerators and
811 // other focus related actions.
812 // The default implementation returns false, ensuring that tab traversal and
813 // accelerators processing is performed.
814 // Subclasses should return true if they want to process the key event and not
815 // have it processed as an accelerator (if any) or as a tab traversal (if the
816 // key event is for the TAB key). In that case, OnKeyPressed will
817 // subsequently be invoked for that event.
818 virtual bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& event);
820 // Subclasses that contain traversable children that are not directly
821 // accessible through the children hierarchy should return the associated
822 // FocusTraversable for the focus traversal to work properly.
823 virtual FocusTraversable* GetFocusTraversable();
825 // Subclasses that can act as a "pane" must implement their own
826 // FocusTraversable to keep the focus trapped within the pane.
827 // If this method returns an object, any view that's a direct or
828 // indirect child of this view will always use this FocusTraversable
829 // rather than the one from the widget.
830 virtual FocusTraversable* GetPaneFocusTraversable();
832 // Tooltips ------------------------------------------------------------------
834 // Gets the tooltip for this View. If the View does not have a tooltip,
835 // return false. If the View does have a tooltip, copy the tooltip into
836 // the supplied string and return true.
837 // Any time the tooltip text that a View is displaying changes, it must
838 // invoke TooltipTextChanged.
839 // |p| provides the coordinates of the mouse (relative to this view).
840 virtual bool GetTooltipText(const gfx::Point& p,
841 base::string16* tooltip) const;
843 // Returns the location (relative to this View) for the text on the tooltip
844 // to display. If false is returned (the default), the tooltip is placed at
845 // a default position.
846 virtual bool GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* loc) const;
848 // Context menus -------------------------------------------------------------
850 // Sets the ContextMenuController. Setting this to non-null makes the View
851 // process mouse events.
852 ContextMenuController* context_menu_controller() {
853 return context_menu_controller_;
855 void set_context_menu_controller(ContextMenuController* menu_controller) {
856 context_menu_controller_ = menu_controller;
859 // Provides default implementation for context menu handling. The default
860 // implementation calls the ShowContextMenu of the current
861 // ContextMenuController (if it is not NULL). Overridden in subclassed views
862 // to provide right-click menu display triggerd by the keyboard (i.e. for the
863 // Chrome toolbar Back and Forward buttons). No source needs to be specified,
864 // as it is always equal to the current View.
865 virtual void ShowContextMenu(const gfx::Point& p,
866 ui::MenuSourceType source_type);
868 // On some platforms, we show context menu on mouse press instead of release.
869 // This method returns true for those platforms.
870 static bool ShouldShowContextMenuOnMousePress();
872 // Drag and drop -------------------------------------------------------------
874 DragController* drag_controller() { return drag_controller_; }
875 void set_drag_controller(DragController* drag_controller) {
876 drag_controller_ = drag_controller;
879 // During a drag and drop session when the mouse moves the view under the
880 // mouse is queried for the drop types it supports by way of the
881 // GetDropFormats methods. If the view returns true and the drag site can
882 // provide data in one of the formats, the view is asked if the drop data
883 // is required before any other drop events are sent. Once the
884 // data is available the view is asked if it supports the drop (by way of
885 // the CanDrop method). If a view returns true from CanDrop,
886 // OnDragEntered is sent to the view when the mouse first enters the view,
887 // as the mouse moves around within the view OnDragUpdated is invoked.
888 // If the user releases the mouse over the view and OnDragUpdated returns a
889 // valid drop, then OnPerformDrop is invoked. If the mouse moves outside the
890 // view or over another view that wants the drag, OnDragExited is invoked.
892 // Similar to mouse events, the deepest view under the mouse is first checked
893 // if it supports the drop (Drop). If the deepest view under
894 // the mouse does not support the drop, the ancestors are walked until one
895 // is found that supports the drop.
897 // Override and return the set of formats that can be dropped on this view.
898 // |formats| is a bitmask of the formats defined bye OSExchangeData::Format.
899 // The default implementation returns false, which means the view doesn't
900 // support dropping.
901 virtual bool GetDropFormats(
902 int* formats,
903 std::set<OSExchangeData::CustomFormat>* custom_formats);
905 // Override and return true if the data must be available before any drop
906 // methods should be invoked. The default is false.
907 virtual bool AreDropTypesRequired();
909 // A view that supports drag and drop must override this and return true if
910 // data contains a type that may be dropped on this view.
911 virtual bool CanDrop(const OSExchangeData& data);
913 // OnDragEntered is invoked when the mouse enters this view during a drag and
914 // drop session and CanDrop returns true. This is immediately
915 // followed by an invocation of OnDragUpdated, and eventually one of
916 // OnDragExited or OnPerformDrop.
917 virtual void OnDragEntered(const ui::DropTargetEvent& event);
919 // Invoked during a drag and drop session while the mouse is over the view.
920 // This should return a bitmask of the DragDropTypes::DragOperation supported
921 // based on the location of the event. Return 0 to indicate the drop should
922 // not be accepted.
923 virtual int OnDragUpdated(const ui::DropTargetEvent& event);
925 // Invoked during a drag and drop session when the mouse exits the views, or
926 // when the drag session was canceled and the mouse was over the view.
927 virtual void OnDragExited();
929 // Invoked during a drag and drop session when OnDragUpdated returns a valid
930 // operation and the user release the mouse.
931 virtual int OnPerformDrop(const ui::DropTargetEvent& event);
933 // Invoked from DoDrag after the drag completes. This implementation does
934 // nothing, and is intended for subclasses to do cleanup.
935 virtual void OnDragDone();
937 // Returns true if the mouse was dragged enough to start a drag operation.
938 // delta_x and y are the distance the mouse was dragged.
939 static bool ExceededDragThreshold(const gfx::Vector2d& delta);
941 // Accessibility -------------------------------------------------------------
943 // Modifies |state| to reflect the current accessible state of this view.
944 virtual void GetAccessibleState(ui::AXViewState* state) { }
946 // Returns an instance of the native accessibility interface for this view.
947 virtual gfx::NativeViewAccessible GetNativeViewAccessible();
949 // Notifies assistive technology that an accessibility event has
950 // occurred on this view, such as when the view is focused or when its
951 // value changes. Pass true for |send_native_event| except for rare
952 // cases where the view is a native control that's already sending a
953 // native accessibility event and the duplicate event would cause
954 // problems.
955 void NotifyAccessibilityEvent(ui::AXEvent event_type,
956 bool send_native_event);
958 // Scrolling -----------------------------------------------------------------
959 // TODO(beng): Figure out if this can live somewhere other than View, i.e.
960 // closer to ScrollView.
962 // Scrolls the specified region, in this View's coordinate system, to be
963 // visible. View's implementation passes the call onto the parent View (after
964 // adjusting the coordinates). It is up to views that only show a portion of
965 // the child view, such as Viewport, to override appropriately.
966 virtual void ScrollRectToVisible(const gfx::Rect& rect);
968 // The following methods are used by ScrollView to determine the amount
969 // to scroll relative to the visible bounds of the view. For example, a
970 // return value of 10 indicates the scrollview should scroll 10 pixels in
971 // the appropriate direction.
973 // Each method takes the following parameters:
975 // is_horizontal: if true, scrolling is along the horizontal axis, otherwise
976 // the vertical axis.
977 // is_positive: if true, scrolling is by a positive amount. Along the
978 // vertical axis scrolling by a positive amount equates to
979 // scrolling down.
981 // The return value should always be positive and gives the number of pixels
982 // to scroll. ScrollView interprets a return value of 0 (or negative)
983 // to scroll by a default amount.
985 // See VariableRowHeightScrollHelper and FixedRowHeightScrollHelper for
986 // implementations of common cases.
987 virtual int GetPageScrollIncrement(ScrollView* scroll_view,
988 bool is_horizontal, bool is_positive);
989 virtual int GetLineScrollIncrement(ScrollView* scroll_view,
990 bool is_horizontal, bool is_positive);
992 protected:
993 // Used to track a drag. RootView passes this into
994 // ProcessMousePressed/Dragged.
995 struct DragInfo {
996 // Sets possible_drag to false and start_x/y to 0. This is invoked by
997 // RootView prior to invoke ProcessMousePressed.
998 void Reset();
1000 // Sets possible_drag to true and start_pt to the specified point.
1001 // This is invoked by the target view if it detects the press may generate
1002 // a drag.
1003 void PossibleDrag(const gfx::Point& p);
1005 // Whether the press may generate a drag.
1006 bool possible_drag;
1008 // Coordinates of the mouse press.
1009 gfx::Point start_pt;
1012 // Size and disposition ------------------------------------------------------
1014 // Override to be notified when the bounds of the view have changed.
1015 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds);
1017 // Called when the preferred size of a child view changed. This gives the
1018 // parent an opportunity to do a fresh layout if that makes sense.
1019 virtual void ChildPreferredSizeChanged(View* child) {}
1021 // Called when the visibility of a child view changed. This gives the parent
1022 // an opportunity to do a fresh layout if that makes sense.
1023 virtual void ChildVisibilityChanged(View* child) {}
1025 // Invalidates the layout and calls ChildPreferredSizeChanged on the parent
1026 // if there is one. Be sure to call View::PreferredSizeChanged when
1027 // overriding such that the layout is properly invalidated.
1028 virtual void PreferredSizeChanged();
1030 // Override returning true when the view needs to be notified when its visible
1031 // bounds relative to the root view may have changed. Only used by
1032 // NativeViewHost.
1033 virtual bool NeedsNotificationWhenVisibleBoundsChange() const;
1035 // Notification that this View's visible bounds relative to the root view may
1036 // have changed. The visible bounds are the region of the View not clipped by
1037 // its ancestors. This is used for clipping NativeViewHost.
1038 virtual void OnVisibleBoundsChanged();
1040 // Override to be notified when the enabled state of this View has
1041 // changed. The default implementation calls SchedulePaint() on this View.
1042 virtual void OnEnabledChanged();
1044 bool needs_layout() const { return needs_layout_; }
1046 // Tree operations -----------------------------------------------------------
1048 // This method is invoked when the tree changes.
1050 // When a view is removed, it is invoked for all children and grand
1051 // children. For each of these views, a notification is sent to the
1052 // view and all parents.
1054 // When a view is added, a notification is sent to the view, all its
1055 // parents, and all its children (and grand children)
1057 // Default implementation does nothing. Override to perform operations
1058 // required when a view is added or removed from a view hierarchy
1060 // Refer to comments in struct |ViewHierarchyChangedDetails| for |details|.
1061 virtual void ViewHierarchyChanged(const ViewHierarchyChangedDetails& details);
1063 // When SetVisible() changes the visibility of a view, this method is
1064 // invoked for that view as well as all the children recursively.
1065 virtual void VisibilityChanged(View* starting_from, bool is_visible);
1067 // This method is invoked when the parent NativeView of the widget that the
1068 // view is attached to has changed and the view hierarchy has not changed.
1069 // ViewHierarchyChanged() is called when the parent NativeView of the widget
1070 // that the view is attached to is changed as a result of changing the view
1071 // hierarchy. Overriding this method is useful for tracking which
1072 // FocusManager manages this view.
1073 virtual void NativeViewHierarchyChanged();
1075 // Painting ------------------------------------------------------------------
1077 // Responsible for calling Paint() on child Views. Override to control the
1078 // order child Views are painted.
1079 virtual void PaintChildren(gfx::Canvas* canvas);
1081 // Override to provide rendering in any part of the View's bounds. Typically
1082 // this is the "contents" of the view. If you override this method you will
1083 // have to call the subsequent OnPaint*() methods manually.
1084 virtual void OnPaint(gfx::Canvas* canvas);
1086 // Override to paint a background before any content is drawn. Typically this
1087 // is done if you are satisfied with a default OnPaint handler but wish to
1088 // supply a different background.
1089 virtual void OnPaintBackground(gfx::Canvas* canvas);
1091 // Override to paint a border not specified by SetBorder().
1092 virtual void OnPaintBorder(gfx::Canvas* canvas);
1094 // Accelerated painting ------------------------------------------------------
1096 // Returns the offset from this view to the nearest ancestor with a layer. If
1097 // |layer_parent| is non-NULL it is set to the nearest ancestor with a layer.
1098 virtual gfx::Vector2d CalculateOffsetToAncestorWithLayer(
1099 ui::Layer** layer_parent);
1101 // Updates the view's layer's parent. Called when a view is added to a view
1102 // hierarchy, responsible for parenting the view's layer to the enclosing
1103 // layer in the hierarchy.
1104 virtual void UpdateParentLayer();
1106 // If this view has a layer, the layer is reparented to |parent_layer| and its
1107 // bounds is set based on |point|. If this view does not have a layer, then
1108 // recurses through all children. This is used when adding a layer to an
1109 // existing view to make sure all descendants that have layers are parented to
1110 // the right layer.
1111 void MoveLayerToParent(ui::Layer* parent_layer, const gfx::Point& point);
1113 // Called to update the bounds of any child layers within this View's
1114 // hierarchy when something happens to the hierarchy.
1115 void UpdateChildLayerBounds(const gfx::Vector2d& offset);
1117 // Overridden from ui::LayerDelegate:
1118 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE;
1119 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
1120 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE;
1122 // Finds the layer that this view paints to (it may belong to an ancestor
1123 // view), then reorders the immediate children of that layer to match the
1124 // order of the view tree.
1125 virtual void ReorderLayers();
1127 // This reorders the immediate children of |*parent_layer| to match the
1128 // order of the view tree. Child layers which are owned by a view are
1129 // reordered so that they are below any child layers not owned by a view.
1130 // Widget::ReorderNativeViews() should be called to reorder any child layers
1131 // with an associated view. Widget::ReorderNativeViews() may reorder layers
1132 // below layers owned by a view.
1133 virtual void ReorderChildLayers(ui::Layer* parent_layer);
1135 // Input ---------------------------------------------------------------------
1137 // Called by HitTestRect() to see if this View has a custom hit test mask. If
1138 // the return value is true, GetHitTestMask() will be called to obtain the
1139 // mask. Default value is false, in which case the View will hit-test against
1140 // its bounds.
1141 virtual bool HasHitTestMask() const;
1143 // Called by HitTestRect() to retrieve a mask for hit-testing against.
1144 // Subclasses override to provide custom shaped hit test regions.
1145 virtual void GetHitTestMask(HitTestSource source, gfx::Path* mask) const;
1147 virtual DragInfo* GetDragInfo();
1149 // Focus ---------------------------------------------------------------------
1151 // Returns last value passed to SetFocusable(). Use IsFocusable() to determine
1152 // if a view can take focus right now.
1153 bool focusable() const { return focusable_; }
1155 // Override to be notified when focus has changed either to or from this View.
1156 virtual void OnFocus();
1157 virtual void OnBlur();
1159 // Handle view focus/blur events for this view.
1160 void Focus();
1161 void Blur();
1163 // System events -------------------------------------------------------------
1165 // Called when the UI theme (not the NativeTheme) has changed, overriding
1166 // allows individual Views to do special cleanup and processing (such as
1167 // dropping resource caches). To dispatch a theme changed notification, call
1168 // Widget::ThemeChanged().
1169 virtual void OnThemeChanged() {}
1171 // Called when the locale has changed, overriding allows individual Views to
1172 // update locale-dependent strings.
1173 // To dispatch a locale changed notification, call Widget::LocaleChanged().
1174 virtual void OnLocaleChanged() {}
1176 // Tooltips ------------------------------------------------------------------
1178 // Views must invoke this when the tooltip text they are to display changes.
1179 void TooltipTextChanged();
1181 // Context menus -------------------------------------------------------------
1183 // Returns the location, in screen coordinates, to show the context menu at
1184 // when the context menu is shown from the keyboard. This implementation
1185 // returns the middle of the visible region of this view.
1187 // This method is invoked when the context menu is shown by way of the
1188 // keyboard.
1189 virtual gfx::Point GetKeyboardContextMenuLocation();
1191 // Drag and drop -------------------------------------------------------------
1193 // These are cover methods that invoke the method of the same name on
1194 // the DragController. Subclasses may wish to override rather than install
1195 // a DragController.
1196 // See DragController for a description of these methods.
1197 virtual int GetDragOperations(const gfx::Point& press_pt);
1198 virtual void WriteDragData(const gfx::Point& press_pt, OSExchangeData* data);
1200 // Returns whether we're in the middle of a drag session that was initiated
1201 // by us.
1202 bool InDrag();
1204 // Returns how much the mouse needs to move in one direction to start a
1205 // drag. These methods cache in a platform-appropriate way. These values are
1206 // used by the public static method ExceededDragThreshold().
1207 static int GetHorizontalDragThreshold();
1208 static int GetVerticalDragThreshold();
1210 // NativeTheme ---------------------------------------------------------------
1212 // Invoked when the NativeTheme associated with this View changes.
1213 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) {}
1215 // Debugging -----------------------------------------------------------------
1217 #if !defined(NDEBUG)
1218 // Returns string containing a graph of the views hierarchy in graphViz DOT
1219 // language (http://graphviz.org/). Can be called within debugger and save
1220 // to a file to compile/view.
1221 // Note: Assumes initial call made with first = true.
1222 virtual std::string PrintViewGraph(bool first);
1224 // Some classes may own an object which contains the children to displayed in
1225 // the views hierarchy. The above function gives the class the flexibility to
1226 // decide which object should be used to obtain the children, but this
1227 // function makes the decision explicit.
1228 std::string DoPrintViewGraph(bool first, View* view_with_children);
1229 #endif
1231 private:
1232 friend class internal::PreEventDispatchHandler;
1233 friend class internal::PostEventDispatchHandler;
1234 friend class internal::RootView;
1235 friend class FocusManager;
1236 friend class Widget;
1238 // Painting -----------------------------------------------------------------
1240 enum SchedulePaintType {
1241 // Indicates the size is the same (only the origin changed).
1242 SCHEDULE_PAINT_SIZE_SAME,
1244 // Indicates the size changed (and possibly the origin).
1245 SCHEDULE_PAINT_SIZE_CHANGED
1248 // Invoked before and after the bounds change to schedule painting the old and
1249 // new bounds.
1250 void SchedulePaintBoundsChanged(SchedulePaintType type);
1252 // Common Paint() code shared by accelerated and non-accelerated code paths to
1253 // invoke OnPaint() on the View.
1254 void PaintCommon(gfx::Canvas* canvas);
1256 // Tree operations -----------------------------------------------------------
1258 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true,
1259 // the next and previous focusable views of views pointing to this view are
1260 // updated. If |update_tool_tip| is true, the tooltip is updated. If
1261 // |delete_removed_view| is true, the view is also deleted (if it is parent
1262 // owned). If |new_parent| is not NULL, the remove is the result of
1263 // AddChildView() to a new parent. For this case, |new_parent| is the View
1264 // that |view| is going to be added to after the remove completes.
1265 void DoRemoveChildView(View* view,
1266 bool update_focus_cycle,
1267 bool update_tool_tip,
1268 bool delete_removed_view,
1269 View* new_parent);
1271 // Call ViewHierarchyChanged() for all child views and all parents.
1272 // |old_parent| is the original parent of the View that was removed.
1273 // If |new_parent| is not NULL, the View that was removed will be reparented
1274 // to |new_parent| after the remove operation.
1275 void PropagateRemoveNotifications(View* old_parent, View* new_parent);
1277 // Call ViewHierarchyChanged() for all children.
1278 void PropagateAddNotifications(const ViewHierarchyChangedDetails& details);
1280 // Propagates NativeViewHierarchyChanged() notification through all the
1281 // children.
1282 void PropagateNativeViewHierarchyChanged();
1284 // Takes care of registering/unregistering accelerators if
1285 // |register_accelerators| true and calls ViewHierarchyChanged().
1286 void ViewHierarchyChangedImpl(bool register_accelerators,
1287 const ViewHierarchyChangedDetails& details);
1289 // Invokes OnNativeThemeChanged() on this and all descendants.
1290 void PropagateNativeThemeChanged(const ui::NativeTheme* theme);
1292 // Size and disposition ------------------------------------------------------
1294 // Call VisibilityChanged() recursively for all children.
1295 void PropagateVisibilityNotifications(View* from, bool is_visible);
1297 // Registers/unregisters accelerators as necessary and calls
1298 // VisibilityChanged().
1299 void VisibilityChangedImpl(View* starting_from, bool is_visible);
1301 // Responsible for propagating bounds change notifications to relevant
1302 // views.
1303 void BoundsChanged(const gfx::Rect& previous_bounds);
1305 // Visible bounds notification registration.
1306 // When a view is added to a hierarchy, it and all its children are asked if
1307 // they need to be registered for "visible bounds within root" notifications
1308 // (see comment on OnVisibleBoundsChanged()). If they do, they are registered
1309 // with every ancestor between them and the root of the hierarchy.
1310 static void RegisterChildrenForVisibleBoundsNotification(View* view);
1311 static void UnregisterChildrenForVisibleBoundsNotification(View* view);
1312 void RegisterForVisibleBoundsNotification();
1313 void UnregisterForVisibleBoundsNotification();
1315 // Adds/removes view to the list of descendants that are notified any time
1316 // this views location and possibly size are changed.
1317 void AddDescendantToNotify(View* view);
1318 void RemoveDescendantToNotify(View* view);
1320 // Sets the layer's bounds given in DIP coordinates.
1321 void SetLayerBounds(const gfx::Rect& bounds_in_dip);
1323 // Transformations -----------------------------------------------------------
1325 // Returns in |transform| the transform to get from coordinates of |ancestor|
1326 // to this. Returns true if |ancestor| is found. If |ancestor| is not found,
1327 // or NULL, |transform| is set to convert from root view coordinates to this.
1328 bool GetTransformRelativeTo(const View* ancestor,
1329 gfx::Transform* transform) const;
1331 // Coordinate conversion -----------------------------------------------------
1333 // Convert a point in the view's coordinate to an ancestor view's coordinate
1334 // system using necessary transformations. Returns whether the point was
1335 // successfully converted to the ancestor's coordinate system.
1336 bool ConvertPointForAncestor(const View* ancestor, gfx::Point* point) const;
1338 // Convert a point in the ancestor's coordinate system to the view's
1339 // coordinate system using necessary transformations. Returns whether the
1340 // point was successfully converted from the ancestor's coordinate system
1341 // to the view's coordinate system.
1342 bool ConvertPointFromAncestor(const View* ancestor, gfx::Point* point) const;
1344 // Convert a rect in the view's coordinate to an ancestor view's coordinate
1345 // system using necessary transformations. Returns whether the rect was
1346 // successfully converted to the ancestor's coordinate system.
1347 bool ConvertRectForAncestor(const View* ancestor, gfx::RectF* rect) const;
1349 // Convert a rect in the ancestor's coordinate system to the view's
1350 // coordinate system using necessary transformations. Returns whether the
1351 // rect was successfully converted from the ancestor's coordinate system
1352 // to the view's coordinate system.
1353 bool ConvertRectFromAncestor(const View* ancestor, gfx::RectF* rect) const;
1355 // Accelerated painting ------------------------------------------------------
1357 // Creates the layer and related fields for this view.
1358 void CreateLayer();
1360 // Parents all un-parented layers within this view's hierarchy to this view's
1361 // layer.
1362 void UpdateParentLayers();
1364 // Parents this view's layer to |parent_layer|, and sets its bounds and other
1365 // properties in accordance to |offset|, the view's offset from the
1366 // |parent_layer|.
1367 void ReparentLayer(const gfx::Vector2d& offset, ui::Layer* parent_layer);
1369 // Called to update the layer visibility. The layer will be visible if the
1370 // View itself, and all its parent Views are visible. This also updates
1371 // visibility of the child layers.
1372 void UpdateLayerVisibility();
1373 void UpdateChildLayerVisibility(bool visible);
1375 // Orphans the layers in this subtree that are parented to layers outside of
1376 // this subtree.
1377 void OrphanLayers();
1379 // Destroys the layer associated with this view, and reparents any descendants
1380 // to the destroyed layer's parent.
1381 void DestroyLayer();
1383 // Input ---------------------------------------------------------------------
1385 bool ProcessMousePressed(const ui::MouseEvent& event);
1386 bool ProcessMouseDragged(const ui::MouseEvent& event);
1387 void ProcessMouseReleased(const ui::MouseEvent& event);
1389 // Accelerators --------------------------------------------------------------
1391 // Registers this view's keyboard accelerators that are not registered to
1392 // FocusManager yet, if possible.
1393 void RegisterPendingAccelerators();
1395 // Unregisters all the keyboard accelerators associated with this view.
1396 // |leave_data_intact| if true does not remove data from accelerators_ array,
1397 // so it could be re-registered with other focus manager
1398 void UnregisterAccelerators(bool leave_data_intact);
1400 // Focus ---------------------------------------------------------------------
1402 // Initialize the previous/next focusable views of the specified view relative
1403 // to the view at the specified index.
1404 void InitFocusSiblings(View* view, int index);
1406 // System events -------------------------------------------------------------
1408 // Used to propagate theme changed notifications from the root view to all
1409 // views in the hierarchy.
1410 virtual void PropagateThemeChanged();
1412 // Used to propagate locale changed notifications from the root view to all
1413 // views in the hierarchy.
1414 virtual void PropagateLocaleChanged();
1416 // Tooltips ------------------------------------------------------------------
1418 // Propagates UpdateTooltip() to the TooltipManager for the Widget.
1419 // This must be invoked any time the View hierarchy changes in such a way
1420 // the view under the mouse differs. For example, if the bounds of a View is
1421 // changed, this is invoked. Similarly, as Views are added/removed, this
1422 // is invoked.
1423 void UpdateTooltip();
1425 // Drag and drop -------------------------------------------------------------
1427 // Starts a drag and drop operation originating from this view. This invokes
1428 // WriteDragData to write the data and GetDragOperations to determine the
1429 // supported drag operations. When done, OnDragDone is invoked. |press_pt| is
1430 // in the view's coordinate system.
1431 // Returns true if a drag was started.
1432 bool DoDrag(const ui::LocatedEvent& event,
1433 const gfx::Point& press_pt,
1434 ui::DragDropTypes::DragEventSource source);
1436 //////////////////////////////////////////////////////////////////////////////
1438 // Creation and lifetime -----------------------------------------------------
1440 // False if this View is owned by its parent - i.e. it will be deleted by its
1441 // parent during its parents destruction. False is the default.
1442 bool owned_by_client_;
1444 // Attributes ----------------------------------------------------------------
1446 // The id of this View. Used to find this View.
1447 int id_;
1449 // The group of this view. Some view subclasses use this id to find other
1450 // views of the same group. For example radio button uses this information
1451 // to find other radio buttons.
1452 int group_;
1454 // Tree operations -----------------------------------------------------------
1456 // This view's parent.
1457 View* parent_;
1459 // This view's children.
1460 Views children_;
1462 // Size and disposition ------------------------------------------------------
1464 // This View's bounds in the parent coordinate system.
1465 gfx::Rect bounds_;
1467 // Whether this view is visible.
1468 bool visible_;
1470 // Whether this view is enabled.
1471 bool enabled_;
1473 // When this flag is on, a View receives a mouse-enter and mouse-leave event
1474 // even if a descendant View is the event-recipient for the real mouse
1475 // events. When this flag is turned on, and mouse moves from outside of the
1476 // view into a child view, both the child view and this view receives
1477 // mouse-enter event. Similarly, if the mouse moves from inside a child view
1478 // and out of this view, then both views receive a mouse-leave event.
1479 // When this flag is turned off, if the mouse moves from inside this view into
1480 // a child view, then this view receives a mouse-leave event. When this flag
1481 // is turned on, it does not receive the mouse-leave event in this case.
1482 // When the mouse moves from inside the child view out of the child view but
1483 // still into this view, this view receives a mouse-enter event if this flag
1484 // is turned off, but doesn't if this flag is turned on.
1485 // This flag is initialized to false.
1486 bool notify_enter_exit_on_child_;
1488 // Whether or not RegisterViewForVisibleBoundsNotification on the RootView
1489 // has been invoked.
1490 bool registered_for_visible_bounds_notification_;
1492 // List of descendants wanting notification when their visible bounds change.
1493 scoped_ptr<Views> descendants_to_notify_;
1495 // Transformations -----------------------------------------------------------
1497 // Clipping parameters. skia transformation matrix does not give us clipping.
1498 // So we do it ourselves.
1499 gfx::Insets clip_insets_;
1501 // Layout --------------------------------------------------------------------
1503 // Whether the view needs to be laid out.
1504 bool needs_layout_;
1506 // The View's LayoutManager defines the sizing heuristics applied to child
1507 // Views. The default is absolute positioning according to bounds_.
1508 scoped_ptr<LayoutManager> layout_manager_;
1510 // Painting ------------------------------------------------------------------
1512 // Background
1513 scoped_ptr<Background> background_;
1515 // Border.
1516 scoped_ptr<Border> border_;
1518 // RTL painting --------------------------------------------------------------
1520 // Indicates whether or not the gfx::Canvas object passed to View::Paint()
1521 // is going to be flipped horizontally (using the appropriate transform) on
1522 // right-to-left locales for this View.
1523 bool flip_canvas_on_paint_for_rtl_ui_;
1525 // Accelerated painting ------------------------------------------------------
1527 bool paint_to_layer_;
1529 // Accelerators --------------------------------------------------------------
1531 // Focus manager accelerators registered on.
1532 FocusManager* accelerator_focus_manager_;
1534 // The list of accelerators. List elements in the range
1535 // [0, registered_accelerator_count_) are already registered to FocusManager,
1536 // and the rest are not yet.
1537 scoped_ptr<std::vector<ui::Accelerator> > accelerators_;
1538 size_t registered_accelerator_count_;
1540 // Focus ---------------------------------------------------------------------
1542 // Next view to be focused when the Tab key is pressed.
1543 View* next_focusable_view_;
1545 // Next view to be focused when the Shift-Tab key combination is pressed.
1546 View* previous_focusable_view_;
1548 // Whether this view can be focused.
1549 bool focusable_;
1551 // Whether this view is focusable if the user requires full keyboard access,
1552 // even though it may not be normally focusable.
1553 bool accessibility_focusable_;
1555 // Context menus -------------------------------------------------------------
1557 // The menu controller.
1558 ContextMenuController* context_menu_controller_;
1560 // Drag and drop -------------------------------------------------------------
1562 DragController* drag_controller_;
1564 // Input --------------------------------------------------------------------
1566 scoped_ptr<internal::PostEventDispatchHandler> post_dispatch_handler_;
1567 scoped_ptr<ui::EventTargeter> targeter_;
1569 // Accessibility -------------------------------------------------------------
1571 // Belongs to this view, but it's reference-counted on some platforms
1572 // so we can't use a scoped_ptr. It's dereferenced in the destructor.
1573 NativeViewAccessibility* native_view_accessibility_;
1575 DISALLOW_COPY_AND_ASSIGN(View);
1578 } // namespace views
1580 #endif // UI_VIEWS_VIEW_H_