blob: a3c60501860a56c6e8f57f48f65dde1145d9ad6b [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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
initial.commit09911bf2008-07-26 23:55:298
[email protected]8c117712009-01-13 12:26:469#include "build/build_config.h"
10
[email protected]1bc83062009-02-06 00:16:3711#include <algorithm>
initial.commit09911bf2008-07-26 23:55:2912#include <map>
[email protected]134c47b92009-08-19 03:33:4413#include <set>
[email protected]1bc83062009-02-06 00:16:3714#include <string>
initial.commit09911bf2008-07-26 23:55:2915#include <vector>
16
[email protected]134c47b92009-08-19 03:33:4417#include "app/os_exchange_data.h"
[email protected]c2f4bdb72010-05-10 23:15:2118#include "base/i18n/rtl.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/scoped_ptr.h"
[email protected]5c7293a2010-03-17 06:40:5720#include "gfx/native_widget_types.h"
[email protected]e0fc2f12010-03-14 23:30:5921#include "gfx/rect.h"
[email protected]2362e4f2009-05-08 00:34:0522#include "views/accelerator.h"
[email protected]91e81ae2009-05-08 22:14:3823#include "views/accessibility/accessibility_types.h"
[email protected]2362e4f2009-05-08 00:34:0524#include "views/background.h"
25#include "views/border.h"
initial.commit09911bf2008-07-26 23:55:2926
[email protected]1eb89e82008-08-15 12:27:0327namespace gfx {
[email protected]82522512009-05-15 07:37:2928class Canvas;
[email protected]1eb89e82008-08-15 12:27:0329class Insets;
[email protected]82739cf2008-09-16 00:37:5630class Path;
[email protected]1eb89e82008-08-15 12:27:0331}
32
[email protected]4a190632009-05-09 01:07:4233class ThemeProvider;
[email protected]5fe15722010-10-22 00:03:2234class ViewAccessibility;
initial.commit09911bf2008-07-26 23:55:2935
[email protected]c2dacc92008-10-16 23:51:3836namespace views {
initial.commit09911bf2008-07-26 23:55:2937
38class Background;
39class Border;
40class FocusManager;
41class FocusTraversable;
42class LayoutManager;
initial.commit09911bf2008-07-26 23:55:2943class RootView;
44class ScrollView;
[email protected]a0dde122008-11-21 20:51:2045class Widget;
[email protected]cd8c47902009-04-30 20:55:3546class Window;
initial.commit09911bf2008-07-26 23:55:2947
48// ContextMenuController is responsible for showing the context menu for a
49// View. To use a ContextMenuController invoke SetContextMenuController on a
50// View. When the appropriate user gesture occurs ShowContextMenu is invoked
51// on the ContextMenuController.
52//
53// Setting a ContextMenuController on a view makes the view process mouse
54// events.
55//
56// It is up to subclasses that do their own mouse processing to invoke
57// the appropriate ContextMenuController method, typically by invoking super's
58// implementation for mouse processing.
59//
60class ContextMenuController {
61 public:
[email protected]e9adf0702010-03-08 23:34:0762 // Invoked to show the context menu for the source view. If |is_mouse_gesture|
63 // is true, |p| is the location of the mouse. If |is_mouse_gesture| is false,
64 // this method was not invoked by a mouse gesture and |p| is the recommended
65 // location to show the menu at.
initial.commit09911bf2008-07-26 23:55:2966 //
[email protected]e9adf0702010-03-08 23:34:0767 // |p| is in screen coordinates.
initial.commit09911bf2008-07-26 23:55:2968 virtual void ShowContextMenu(View* source,
[email protected]e9adf0702010-03-08 23:34:0769 const gfx::Point& p,
initial.commit09911bf2008-07-26 23:55:2970 bool is_mouse_gesture) = 0;
[email protected]20cb5f482009-12-16 01:01:2571
72 protected:
73 virtual ~ContextMenuController() {}
initial.commit09911bf2008-07-26 23:55:2974};
75
76// DragController is responsible for writing drag data for a view, as well as
77// supplying the supported drag operations. Use DragController if you don't
78// want to subclass.
79
80class DragController {
81 public:
82 // Writes the data for the drag.
83 virtual void WriteDragData(View* sender,
[email protected]e9adf0702010-03-08 23:34:0784 const gfx::Point& press_pt,
initial.commit09911bf2008-07-26 23:55:2985 OSExchangeData* data) = 0;
86
87 // Returns the supported drag operations (see DragDropTypes for possible
88 // values). A drag is only started if this returns a non-zero value.
[email protected]e9adf0702010-03-08 23:34:0789 virtual int GetDragOperations(View* sender, const gfx::Point& p) = 0;
initial.commit09911bf2008-07-26 23:55:2990
[email protected]b5f94de2009-12-04 07:59:0091 // Returns true if a drag operation can be started.
[email protected]e9adf0702010-03-08 23:34:0792 // |press_pt| represents the coordinates where the mouse was initially
93 // pressed down. |p| is the current mouse coordinates.
[email protected]b5f94de2009-12-04 07:59:0094 virtual bool CanStartDrag(View* sender,
[email protected]e9adf0702010-03-08 23:34:0795 const gfx::Point& press_pt,
96 const gfx::Point& p) = 0;
[email protected]20cb5f482009-12-16 01:01:2597
98 protected:
99 virtual ~DragController() {}
[email protected]b5f94de2009-12-04 07:59:00100};
initial.commit09911bf2008-07-26 23:55:29101
102/////////////////////////////////////////////////////////////////////////////
103//
104// View class
105//
[email protected]c2dacc92008-10-16 23:51:38106// A View is a rectangle within the views View hierarchy. It is the base
[email protected]1bc83062009-02-06 00:16:37107// class for all Views.
initial.commit09911bf2008-07-26 23:55:29108//
109// A View is a container of other Views (there is no such thing as a Leaf
110// View - makes code simpler, reduces type conversion headaches, design
111// mistakes etc)
112//
113// The View contains basic properties for sizing (bounds), layout (flex,
114// orientation, etc), painting of children and event dispatch.
115//
116// The View also uses a simple Box Layout Manager similar to XUL's
117// SprocketLayout system. Alternative Layout Managers implementing the
118// LayoutManager interface can be used to lay out children if required.
119//
120// It is up to the subclass to implement Painting and storage of subclass -
121// specific properties and functionality.
122//
123/////////////////////////////////////////////////////////////////////////////
124class View : public AcceleratorTarget {
125 public:
[email protected]6f3bb6c2008-09-17 22:25:33126 // Used in the versions of GetBounds() and x() that take a transformation
initial.commit09911bf2008-07-26 23:55:29127 // parameter in order to determine whether or not to take into account the
128 // mirroring setting of the View when returning bounds positions.
129 enum PositionMirroringSettings {
130 IGNORE_MIRRORING_TRANSFORMATION = 0,
131 APPLY_MIRRORING_TRANSFORMATION
132 };
133
134 // The view class name.
135 static char kViewClassName[];
136
137 View();
138 virtual ~View();
139
[email protected]aadcd1d92009-09-22 18:11:31140 // Returns the amount of time between double clicks, in milliseconds.
141 static int GetDoubleClickTimeMS();
142
[email protected]8af4c1992010-02-04 21:38:07143 // Returns the amount of time to wait from hovering over a menu button until
144 // showing the menu.
145 static int GetMenuShowDelay();
146
initial.commit09911bf2008-07-26 23:55:29147 // Sizing functions
148
149 // Get the bounds of the View, relative to the parent. Essentially, this
150 // function returns the bounds_ rectangle.
151 //
152 // This is the function subclasses should use whenever they need to obtain
153 // the bounds of one of their child views (for example, when implementing
154 // View::Layout()).
[email protected]24db2eb2009-07-17 17:54:16155 const gfx::Rect& bounds() const { return bounds_; }
[email protected]80f8b9f2008-10-16 18:17:47156
157 // Get the size of the View.
[email protected]24db2eb2009-07-17 17:54:16158 const gfx::Size& size() const { return bounds_.size(); }
initial.commit09911bf2008-07-26 23:55:29159
160 // Return the bounds of the View, relative to the parent. If
161 // |settings| is IGNORE_MIRRORING_TRANSFORMATION, the function returns the
[email protected]8f763a302009-11-11 00:47:32162 // bounds_ rectangle. If |settings| is APPLY_MIRRORING_TRANSFORMATION AND the
initial.commit09911bf2008-07-26 23:55:29163 // parent View is using a right-to-left UI layout, then the function returns
164 // a shifted version of the bounds_ rectangle that represents the mirrored
165 // View bounds.
166 //
167 // NOTE: in the vast majority of the cases, the mirroring implementation is
168 // transparent to the View subclasses and therefore you should use the
169 // version of GetBounds() which does not take a transformation settings
170 // parameter.
[email protected]0d8ea702008-10-14 17:03:07171 gfx::Rect GetBounds(PositionMirroringSettings settings) const;
initial.commit09911bf2008-07-26 23:55:29172
173 // Set the bounds in the parent's coordinate system.
[email protected]80f8b9f2008-10-16 18:17:47174 void SetBounds(const gfx::Rect& bounds);
175 void SetBounds(int x, int y, int width, int height) {
176 SetBounds(gfx::Rect(x, y, std::max(0, width), std::max(0, height)));
177 }
[email protected]6f3bb6c2008-09-17 22:25:33178 void SetX(int x) { SetBounds(x, y(), width(), height()); }
179 void SetY(int y) { SetBounds(x(), y, width(), height()); }
initial.commit09911bf2008-07-26 23:55:29180
181 // Returns the left coordinate of the View, relative to the parent View,
[email protected]80f8b9f2008-10-16 18:17:47182 // which is the value of bounds_.x().
initial.commit09911bf2008-07-26 23:55:29183 //
184 // This is the function subclasses should use whenever they need to obtain
185 // the left position of one of their child views (for example, when
186 // implementing View::Layout()).
[email protected]0a1d36b22008-10-17 19:33:09187 // This is equivalent to GetX(IGNORE_MIRRORING_TRANSFORMATION), but
188 // inlinable.
189 int x() const { return bounds_.x(); }
190 int y() const { return bounds_.y(); }
191 int width() const { return bounds_.width(); }
192 int height() const { return bounds_.height(); }
initial.commit09911bf2008-07-26 23:55:29193
194 // Return the left coordinate of the View, relative to the parent. If
195 // |settings| is IGNORE_MIRRORING_SETTINGS, the function returns the value of
[email protected]80f8b9f2008-10-16 18:17:47196 // bounds_.x(). If |settings| is APPLY_MIRRORING_SETTINGS AND the parent
initial.commit09911bf2008-07-26 23:55:29197 // View is using a right-to-left UI layout, then the function returns the
[email protected]80f8b9f2008-10-16 18:17:47198 // mirrored value of bounds_.x().
initial.commit09911bf2008-07-26 23:55:29199 //
200 // NOTE: in the vast majority of the cases, the mirroring implementation is
201 // transparent to the View subclasses and therefore you should use the
[email protected]6f3bb6c2008-09-17 22:25:33202 // paremeterless version of x() when you need to get the X
initial.commit09911bf2008-07-26 23:55:29203 // coordinate of a child View.
204 int GetX(PositionMirroringSettings settings) const;
205
initial.commit09911bf2008-07-26 23:55:29206 // Return this control local bounds. If include_border is true, local bounds
[email protected]6f3bb6c2008-09-17 22:25:33207 // is the rectangle {0, 0, width(), height()}, otherwise, it does not
initial.commit09911bf2008-07-26 23:55:29208 // include the area where the border (if any) is painted.
[email protected]80f8b9f2008-10-16 18:17:47209 gfx::Rect GetLocalBounds(bool include_border) const;
initial.commit09911bf2008-07-26 23:55:29210
211 // Get the position of the View, relative to the parent.
212 //
213 // Note that if the parent uses right-to-left UI layout, then the mirrored
[email protected]6f3bb6c2008-09-17 22:25:33214 // position of this View is returned. Use x()/y() if you want to ignore
initial.commit09911bf2008-07-26 23:55:29215 // mirroring.
[email protected]0a1d36b22008-10-17 19:33:09216 gfx::Point GetPosition() const;
initial.commit09911bf2008-07-26 23:55:29217
218 // Get the size the View would like to be, if enough space were available.
[email protected]154f8bc2008-10-15 18:02:30219 virtual gfx::Size GetPreferredSize();
initial.commit09911bf2008-07-26 23:55:29220
[email protected]a1360162009-11-30 21:19:07221 // Returns the baseline of this view, or -1 if this view has no baseline. The
222 // return value is relative to the preferred height.
223 virtual int GetBaseline();
224
initial.commit09911bf2008-07-26 23:55:29225 // Convenience method that sizes this view to its preferred size.
226 void SizeToPreferredSize();
227
228 // Gets the minimum size of the view. View's implementation invokes
229 // GetPreferredSize.
[email protected]154f8bc2008-10-15 18:02:30230 virtual gfx::Size GetMinimumSize();
initial.commit09911bf2008-07-26 23:55:29231
232 // Return the height necessary to display this view with the provided width.
233 // View's implementation returns the value from getPreferredSize.cy.
234 // Override if your View's preferred height depends upon the width (such
235 // as with Labels).
236 virtual int GetHeightForWidth(int w);
237
238 // This method is invoked when this object size or position changes.
239 // The default implementation does nothing.
[email protected]80f8b9f2008-10-16 18:17:47240 virtual void DidChangeBounds(const gfx::Rect& previous,
241 const gfx::Rect& current);
initial.commit09911bf2008-07-26 23:55:29242
243 // Set whether the receiving view is visible. Painting is scheduled as needed
244 virtual void SetVisible(bool flag);
245
246 // Return whether a view is visible
247 virtual bool IsVisible() const { return is_visible_; }
248
249 // Return whether a view and its ancestors are visible. Returns true if the
250 // path from this view to the root view is visible.
251 virtual bool IsVisibleInRootView() const;
252
253 // Set whether this view is enabled. A disabled view does not receive keyboard
254 // or mouse inputs. If flag differs from the current value, SchedulePaint is
255 // invoked.
256 virtual void SetEnabled(bool flag);
257
258 // Returns whether the view is enabled.
259 virtual bool IsEnabled() const;
260
261 // Set whether this view is hottracked. A disabled view cannot be hottracked.
262 // If flag differs from the current value, SchedulePaint is invoked.
263 virtual void SetHotTracked(bool flag);
264
265 // Returns whether the view is hot-tracked.
266 virtual bool IsHotTracked() const { return false; }
267
[email protected]b82a0492010-05-27 23:00:03268 virtual Widget* child_widget() { return NULL; }
269
initial.commit09911bf2008-07-26 23:55:29270 // Returns whether the view is pushed.
271 virtual bool IsPushed() const { return false; }
272
273 // Scrolls the specified region, in this View's coordinate system, to be
274 // visible. View's implementation passes the call onto the parent View (after
275 // adjusting the coordinates). It is up to views that only show a portion of
276 // the child view, such as Viewport, to override appropriately.
[email protected]e9adf0702010-03-08 23:34:07277 virtual void ScrollRectToVisible(const gfx::Rect& rect);
initial.commit09911bf2008-07-26 23:55:29278
279 // Layout functions
280
281 // Lay out the child Views (set their bounds based on sizing heuristics
282 // specific to the current Layout Manager)
283 virtual void Layout();
284
[email protected]9ea053e2010-07-15 08:19:05285 // Mark this view and all parents to require a relayout. This ensures the
286 // next call to Layout() will propagate to this view, even if the bounds of
287 // parent views do not change.
288 void InvalidateLayout();
289
initial.commit09911bf2008-07-26 23:55:29290 // Gets/Sets the Layout Manager used by this view to size and place its
291 // children.
292 // The LayoutManager is owned by the View and is deleted when the view is
293 // deleted, or when a new LayoutManager is installed.
294 LayoutManager* GetLayoutManager() const;
295 void SetLayoutManager(LayoutManager* layout);
296
297 // Right-to-left UI layout functions
298
[email protected]82522512009-05-15 07:37:29299 // This method determines whether the gfx::Canvas object passed to
initial.commit09911bf2008-07-26 23:55:29300 // View::Paint() needs to be transformed such that anything drawn on the
301 // canvas object during View::Paint() is flipped horizontally.
302 //
303 // By default, this function returns false (which is the initial value of
304 // |flip_canvas_on_paint_for_rtl_ui_|). View subclasses that need to paint on
[email protected]82522512009-05-15 07:37:29305 // a flipped gfx::Canvas when the UI layout is right-to-left need to call
initial.commit09911bf2008-07-26 23:55:29306 // EnableCanvasFlippingForRTLUI().
307 bool FlipCanvasOnPaintForRTLUI() const {
[email protected]c2f4bdb72010-05-10 23:15:21308 return flip_canvas_on_paint_for_rtl_ui_ ? base::i18n::IsRTL() : false;
initial.commit09911bf2008-07-26 23:55:29309 }
310
[email protected]82522512009-05-15 07:37:29311 // Enables or disables flipping of the gfx::Canvas during View::Paint().
initial.commit09911bf2008-07-26 23:55:29312 // Note that if canvas flipping is enabled, the canvas will be flipped only
313 // if the UI layout is right-to-left; that is, the canvas will be flipped
[email protected]c2f4bdb72010-05-10 23:15:21314 // only if base::i18n::IsRTL() returns true.
initial.commit09911bf2008-07-26 23:55:29315 //
316 // Enabling canvas flipping is useful for leaf views that draw a bitmap that
317 // needs to be flipped horizontally when the UI layout is right-to-left
[email protected]c2dacc92008-10-16 23:51:38318 // (views::Button, for example). This method is helpful for such classes
319 // because their drawing logic stays the same and they can become agnostic to
320 // the UI directionality.
initial.commit09911bf2008-07-26 23:55:29321 void EnableCanvasFlippingForRTLUI(bool enable) {
322 flip_canvas_on_paint_for_rtl_ui_ = enable;
323 }
324
325 // Returns the mirrored X position for the view, relative to the parent. If
326 // the parent view is not mirrored, this function returns bound_.left.
327 //
328 // UI mirroring is transparent to most View subclasses and therefore there is
329 // no need to call this routine from anywhere within your subclass
330 // implementation.
[email protected]63329982008-10-10 21:56:57331 int MirroredX() const;
initial.commit09911bf2008-07-26 23:55:29332
333 // Given a rectangle specified in this View's coordinate system, the function
334 // computes the 'left' value for the mirrored rectangle within this View. If
335 // the View's UI layout is not right-to-left, then bounds.x() is returned.
336 //
337 // UI mirroring is transparent to most View subclasses and therefore there is
338 // no need to call this routine from anywhere within your subclass
339 // implementation.
340 int MirroredLeftPointForRect(const gfx::Rect& rect) const;
341
342 // Given the X coordinate of a point inside the View, this function returns
343 // the mirrored X coordinate of the point if the View's UI layout is
344 // right-to-left. If the layout is left-to-right, the same X coordinate is
345 // returned.
346 //
347 // Following are a few examples of the values returned by this function for
348 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout:
349 //
350 // MirroredXCoordinateInsideView(0) -> 100
351 // MirroredXCoordinateInsideView(20) -> 80
352 // MirroredXCoordinateInsideView(99) -> 1
353 int MirroredXCoordinateInsideView(int x) const {
[email protected]c2f4bdb72010-05-10 23:15:21354 return base::i18n::IsRTL() ? width() - x : x;
initial.commit09911bf2008-07-26 23:55:29355 }
356
[email protected]14da3dff2009-06-12 18:01:47357 // Given a X coordinate and a width inside the View, this function returns
358 // the mirrored X coordinate if the View's UI layout is right-to-left. If the
359 // layout is left-to-right, the same X coordinate is returned.
360 //
361 // Following are a few examples of the values returned by this function for
362 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout:
363 //
364 // MirroredXCoordinateInsideView(0, 10) -> 90
365 // MirroredXCoordinateInsideView(20, 20) -> 60
366 int MirroredXWithWidthInsideView(int x, int w) const {
[email protected]c2f4bdb72010-05-10 23:15:21367 return base::i18n::IsRTL() ? width() - x - w : x;
[email protected]14da3dff2009-06-12 18:01:47368 }
369
initial.commit09911bf2008-07-26 23:55:29370 // Painting functions
371
372 // Mark the specified rectangle as dirty (needing repaint). If |urgent| is
373 // true, the view will be repainted when the current event processing is
374 // done. Otherwise, painting will take place as soon as possible.
[email protected]0a1d36b22008-10-17 19:33:09375 virtual void SchedulePaint(const gfx::Rect& r, bool urgent);
initial.commit09911bf2008-07-26 23:55:29376
377 // Mark the entire View's bounds as dirty. Painting will occur as soon as
378 // possible.
379 virtual void SchedulePaint();
380
initial.commit09911bf2008-07-26 23:55:29381 // Paint the receiving view. g is prepared such as it is in
382 // receiver's coordinate system. g's state is restored after this
383 // call so your implementation can change the graphics configuration
384 //
385 // Default implementation paints the background if it is defined
386 //
387 // Override this method when implementing a new control.
[email protected]82522512009-05-15 07:37:29388 virtual void Paint(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29389
390 // Paint the background if any. This method is called by Paint() and
391 // should rarely be invoked directly.
[email protected]82522512009-05-15 07:37:29392 virtual void PaintBackground(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29393
394 // Paint the border if any. This method is called by Paint() and
395 // should rarely be invoked directly.
[email protected]82522512009-05-15 07:37:29396 virtual void PaintBorder(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29397
398 // Paints the focus border (only if the view has the focus).
399 // This method is called by Paint() and should rarely be invoked directly.
400 // The default implementation paints a gray border around the view. Override
401 // it for custom focus effects.
[email protected]82522512009-05-15 07:37:29402 virtual void PaintFocusBorder(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29403
404 // Paint this View immediately.
405 virtual void PaintNow();
406
initial.commit09911bf2008-07-26 23:55:29407 // Tree functions
408
409 // Add a child View.
410 void AddChildView(View* v);
411
412 // Adds a child View at the specified position.
413 void AddChildView(int index, View* v);
414
415 // Get the child View at the specified index.
416 View* GetChildViewAt(int index) const;
417
418 // Remove a child view from this view. v's parent will change to NULL
419 void RemoveChildView(View *v);
420
421 // Remove all child view from this view. If |delete_views| is true, the views
422 // are deleted, unless marked as not parent owned.
423 void RemoveAllChildViews(bool delete_views);
424
425 // Get the number of child Views.
426 int GetChildViewCount() const;
427
[email protected]3a9c26f2010-03-12 21:04:39428 // Tests if this view has a given view as direct child.
429 bool HasChildView(View* a_view);
430
[email protected]24db2eb2009-07-17 17:54:16431 // Returns the deepest descendant that contains the specified point.
[email protected]613b8062008-10-14 23:45:09432 virtual View* GetViewForPoint(const gfx::Point& point);
initial.commit09911bf2008-07-26 23:55:29433
[email protected]a0dde122008-11-21 20:51:20434 // Get the Widget that hosts this View, if any.
435 virtual Widget* GetWidget() const;
initial.commit09911bf2008-07-26 23:55:29436
[email protected]cd8c47902009-04-30 20:55:35437 // Gets the Widget that most closely contains this View, if any.
[email protected]08a3b712009-10-14 18:03:47438 // NOTE: almost all views displayed on screen have a Widget, but not
439 // necessarily a Window. This is due to widgets being able to create top
440 // level windows (as is done for popups, bubbles and menus).
[email protected]cd8c47902009-04-30 20:55:35441 virtual Window* GetWindow() const;
442
[email protected]2db27be2010-02-10 22:46:47443 // Returns true if the native view |native_view| is contained in the view
444 // hierarchy beneath this view.
445 virtual bool ContainsNativeView(gfx::NativeView native_view) const;
446
initial.commit09911bf2008-07-26 23:55:29447 // Get the containing RootView
448 virtual RootView* GetRootView();
449
450 // Get the parent View
451 View* GetParent() const { return parent_; }
452
453 // Returns the index of the specified |view| in this view's children, or -1
454 // if the specified view is not a child of this view.
[email protected]5e26d9d42010-05-13 22:11:03455 int GetChildIndex(const View* v) const;
initial.commit09911bf2008-07-26 23:55:29456
457 // Returns true if the specified view is a direct or indirect child of this
458 // view.
459 bool IsParentOf(View* v) const;
460
461 // Recursively descends the view tree starting at this view, and returns
462 // the first child that it encounters that has the given ID.
463 // Returns NULL if no matching child view is found.
464 virtual View* GetViewByID(int id) const;
465
466 // Sets and gets the ID for this view. ID should be unique within the subtree
467 // that you intend to search for it. 0 is the default ID for views.
468 void SetID(int id);
469 int GetID() const;
470
471 // A group id is used to tag views which are part of the same logical group.
472 // Focus can be moved between views with the same group using the arrow keys.
473 // Groups are currently used to implement radio button mutual exclusion.
[email protected]96f960d2009-09-14 18:45:30474 // The group id is immutable once it's set.
initial.commit09911bf2008-07-26 23:55:29475 void SetGroup(int gid);
[email protected]96f960d2009-09-14 18:45:30476 // Returns the group id of the view, or -1 if the id is not set yet.
initial.commit09911bf2008-07-26 23:55:29477 int GetGroup() const;
478
479 // If this returns true, the views from the same group can each be focused
480 // when moving focus with the Tab/Shift-Tab key. If this returns false,
481 // only the selected view from the group (obtained with
482 // GetSelectedViewForGroup()) is focused.
483 virtual bool IsGroupFocusTraversable() const { return true; }
484
485 // Fills the provided vector with all the available views which belong to the
486 // provided group.
487 void GetViewsWithGroup(int group_id, std::vector<View*>* out);
488
489 // Return the View that is currently selected in the specified group.
490 // The default implementation simply returns the first View found for that
491 // group.
492 virtual View* GetSelectedViewForGroup(int group_id);
493
494 // Focus support
495 //
496 // Returns the view that should be selected next when pressing Tab.
497 View* GetNextFocusableView();
498
499 // Returns the view that should be selected next when pressing Shift-Tab.
500 View* GetPreviousFocusableView();
501
502 // Sets the component that should be selected next when pressing Tab, and
503 // makes the current view the precedent view of the specified one.
504 // Note that by default views are linked in the order they have been added to
505 // their container. Use this method if you want to modify the order.
506 // IMPORTANT NOTE: loops in the focus hierarchy are not supported.
507 void SetNextFocusableView(View* view);
508
initial.commit09911bf2008-07-26 23:55:29509 // Sets whether this view can accept the focus.
510 // Note that this is false by default so that a view used as a container does
511 // not get the focus.
512 virtual void SetFocusable(bool focusable);
513
[email protected]59461d22010-07-21 15:41:09514 // Returns true if the view is focusable (IsFocusable) and visible in the root
515 // view. See also IsFocusable.
516 bool IsFocusableInRootView() const;
517
518 // Return whether this view is focusable when the user requires full keyboard
519 // access, even though it may not be normally focusable.
520 bool IsAccessibilityFocusableInRootView() const;
[email protected]83548a42010-06-18 13:53:37521
522 // Set whether this view can be made focusable if the user requires
523 // full keyboard access, even though it's not normally focusable.
524 // Note that this is false by default.
525 virtual void set_accessibility_focusable(bool accessibility_focusable) {
526 accessibility_focusable_ = accessibility_focusable;
527 }
528
initial.commit09911bf2008-07-26 23:55:29529 // Convenience method to retrieve the FocusManager associated with the
[email protected]a0dde122008-11-21 20:51:20530 // Widget that contains this view. This can return NULL if this view is not
531 // part of a view hierarchy with a Widget.
initial.commit09911bf2008-07-26 23:55:29532 virtual FocusManager* GetFocusManager();
533
534 // Sets a keyboard accelerator for that view. When the user presses the
535 // accelerator key combination, the AcceleratorPressed method is invoked.
536 // Note that you can set multiple accelerators for a view by invoking this
537 // method several times.
538 virtual void AddAccelerator(const Accelerator& accelerator);
539
[email protected]e8e0f362008-11-08 01:13:25540 // Removes the specified accelerator for this view.
541 virtual void RemoveAccelerator(const Accelerator& accelerator);
542
initial.commit09911bf2008-07-26 23:55:29543 // Removes all the keyboard accelerators for this view.
544 virtual void ResetAccelerators();
545
546 // Called when a keyboard accelerator is pressed.
547 // Derived classes should implement desired behavior and return true if they
548 // handled the accelerator.
549 virtual bool AcceleratorPressed(const Accelerator& accelerator) {
550 return false;
551 }
552
initial.commit09911bf2008-07-26 23:55:29553 // Returns whether this view currently has the focus.
554 virtual bool HasFocus();
555
556 // Accessibility support
[email protected]4c671e12010-09-28 19:30:23557 // TODO(ctguil): Move all this out to a AccessibleInfo wrapper class.
[email protected]98703262010-06-18 23:53:41558
559 // Notify the platform specific accessibility client of changes in the user
[email protected]ddd919e2010-07-30 17:32:17560 // interface. This will always raise native notifications.
[email protected]98703262010-06-18 23:53:41561 virtual void NotifyAccessibilityEvent(AccessibilityTypes::Event event_type);
562
[email protected]ddd919e2010-07-30 17:32:17563 // Raise an accessibility notification with an option to also raise a native
564 // notification.
565 virtual void NotifyAccessibilityEvent(AccessibilityTypes::Event event_type,
566 bool send_native_event);
567
initial.commit09911bf2008-07-26 23:55:29568 // Returns the MSAA default action of the current view. The string returned
569 // describes the default action that will occur when executing
570 // IAccessible::DoDefaultAction. For instance, default action of a button is
[email protected]4c671e12010-09-28 19:30:23571 // 'Press'.
572 virtual std::wstring GetAccessibleDefaultAction() { return std::wstring(); }
initial.commit09911bf2008-07-26 23:55:29573
574 // Returns a string containing the mnemonic, or the keyboard shortcut, for a
[email protected]4c671e12010-09-28 19:30:23575 // given control.
576 virtual std::wstring GetAccessibleKeyboardShortcut() {
577 return std::wstring();
initial.commit09911bf2008-07-26 23:55:29578 }
579
580 // Returns a brief, identifying string, containing a unique, readable name of
581 // a given control. Sets the input string appropriately, and returns true if
582 // successful.
[email protected]d5c81012010-04-03 00:56:12583 bool GetAccessibleName(std::wstring* name);
initial.commit09911bf2008-07-26 23:55:29584
[email protected]e92070ac2009-04-28 00:12:01585 // Returns the accessibility role of the current view. The role is what
586 // assistive technologies (ATs) use to determine what behavior to expect from
[email protected]4c671e12010-09-28 19:30:23587 // a given control.
588 virtual AccessibilityTypes::Role GetAccessibleRole();
initial.commit09911bf2008-07-26 23:55:29589
[email protected]4c671e12010-09-28 19:30:23590 // Returns the accessibility state of the current view.
591 virtual AccessibilityTypes::State GetAccessibleState() {
592 return 0;
[email protected]e92070ac2009-04-28 00:12:01593 }
initial.commit09911bf2008-07-26 23:55:29594
[email protected]4c671e12010-09-28 19:30:23595 // Returns the current value associated with a view.
596 virtual std::wstring GetAccessibleValue() { return std::wstring(); }
[email protected]a9d59462010-03-26 21:51:04597
initial.commit09911bf2008-07-26 23:55:29598 // Assigns a string name to the given control. Needed as a View does not know
599 // which name will be associated with it until it is created to be a
600 // certain type.
[email protected]d5c81012010-04-03 00:56:12601 void SetAccessibleName(const std::wstring& name);
[email protected]a9d59462010-03-26 21:51:04602
[email protected]5fe15722010-10-22 00:03:22603 // Returns an instance of the (platform-specific) accessibility interface for
604 // the View.
605 ViewAccessibility* GetViewAccessibility();
initial.commit09911bf2008-07-26 23:55:29606
initial.commit09911bf2008-07-26 23:55:29607 // Utility functions
608
609 // Note that the utility coordinate conversions functions always operate on
610 // the mirrored position of the child Views if the parent View uses a
611 // right-to-left UI layout.
612
613 // Convert a point from source coordinate system to dst coordinate system.
614 //
615 // source is a parent or a child of dst, directly or transitively.
616 // If source and dst are not in the same View hierarchy, the result is
617 // undefined.
618 // Source can be NULL in which case it means the screen coordinate system
[email protected]bb515ed2009-01-15 00:53:43619 static void ConvertPointToView(const View* src,
620 const View* dst,
initial.commit09911bf2008-07-26 23:55:29621 gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29622
623 // Convert a point from the coordinate system of a View to that of the
[email protected]a0dde122008-11-21 20:51:20624 // Widget. This is useful for example when sizing HWND children of the
625 // Widget that don't know about the View hierarchy and need to be placed
626 // relative to the Widget that is their parent.
[email protected]2fb6d462009-02-13 18:40:10627 static void ConvertPointToWidget(const View* src, gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29628
[email protected]a0dde122008-11-21 20:51:20629 // Convert a point from a view Widget to a View dest
[email protected]2fb6d462009-02-13 18:40:10630 static void ConvertPointFromWidget(const View* dest, gfx::Point* p);
initial.commit09911bf2008-07-26 23:55:29631
632 // Convert a point from the coordinate system of a View to that of the
633 // screen. This is useful for example when placing popup windows.
[email protected]2fb6d462009-02-13 18:40:10634 static void ConvertPointToScreen(const View* src, gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29635
[email protected]a0949a42010-08-23 16:03:05636 // Return the bounds of the View in screen coordinate system.
637 gfx::Rect GetScreenBounds() const;
638
initial.commit09911bf2008-07-26 23:55:29639 // Event Handlers
640
641 // This method is invoked when the user clicks on this view.
642 // The provided event is in the receiver's coordinate system.
643 //
644 // Return true if you processed the event and want to receive subsequent
645 // MouseDraggged and MouseReleased events. This also stops the event from
646 // bubbling. If you return false, the event will bubble through parent
647 // views.
648 //
649 // If you remove yourself from the tree while processing this, event bubbling
650 // stops as if you returned true, but you will not receive future events.
651 // The return value is ignored in this case.
652 //
653 // Default implementation returns true if a ContextMenuController has been
654 // set, false otherwise. Override as needed.
655 //
656 virtual bool OnMousePressed(const MouseEvent& event);
657
658 // This method is invoked when the user clicked on this control.
659 // and is still moving the mouse with a button pressed.
660 // The provided event is in the receiver's coordinate system.
661 //
662 // Return true if you processed the event and want to receive
663 // subsequent MouseDragged and MouseReleased events.
664 //
665 // Default implementation returns true if a ContextMenuController has been
666 // set, false otherwise. Override as needed.
667 //
668 virtual bool OnMouseDragged(const MouseEvent& event);
669
670 // This method is invoked when the user releases the mouse
671 // button. The event is in the receiver's coordinate system.
672 //
673 // If canceled is true it indicates the mouse press/drag was canceled by a
674 // system/user gesture.
675 //
676 // Default implementation notifies the ContextMenuController is appropriate.
677 // Subclasses that wish to honor the ContextMenuController should invoke
678 // super.
679 virtual void OnMouseReleased(const MouseEvent& event, bool canceled);
680
681 // This method is invoked when the mouse is above this control
682 // The event is in the receiver's coordinate system.
683 //
684 // Default implementation does nothing. Override as needed.
685 virtual void OnMouseMoved(const MouseEvent& e);
686
687 // This method is invoked when the mouse enters this control.
688 //
689 // Default implementation does nothing. Override as needed.
690 virtual void OnMouseEntered(const MouseEvent& event);
691
692 // This method is invoked when the mouse exits this control
693 // The provided event location is always (0, 0)
694 // Default implementation does nothing. Override as needed.
695 virtual void OnMouseExited(const MouseEvent& event);
696
[email protected]ad84c8f2010-09-08 14:06:10697#if defined(TOUCH_UI)
698 // This method is invoked for each touch event. Default implementation
699 // does nothing. Override as needed.
700 virtual bool OnTouchEvent(const TouchEvent& event);
701#endif
702
initial.commit09911bf2008-07-26 23:55:29703 // Set the MouseHandler for a drag session.
704 //
705 // A drag session is a stream of mouse events starting
706 // with a MousePressed event, followed by several MouseDragged
707 // events and finishing with a MouseReleased event.
708 //
709 // This method should be only invoked while processing a
[email protected]ad84c8f2010-09-08 14:06:10710 // MouseDragged or MousePressed event.
initial.commit09911bf2008-07-26 23:55:29711 //
712 // All further mouse dragged and mouse up events will be sent
713 // the MouseHandler, even if it is reparented to another window.
714 //
715 // The MouseHandler is automatically cleared when the control
716 // comes back from processing the MouseReleased event.
717 //
718 // Note: if the mouse handler is no longer connected to a
719 // view hierarchy, events won't be sent.
720 //
721 virtual void SetMouseHandler(View* new_mouse_handler);
722
723 // Request the keyboard focus. The receiving view will become the
724 // focused view.
725 virtual void RequestFocus();
726
727 // Invoked when a view is about to gain focus
728 virtual void WillGainFocus();
729
730 // Invoked when a view just gained focus.
731 virtual void DidGainFocus();
732
733 // Invoked when a view is about lose focus
734 virtual void WillLoseFocus();
735
736 // Invoked when a view is about to be requested for focus due to the focus
737 // traversal. Reverse is this request was generated going backward
738 // (Shift-Tab).
739 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) { }
740
[email protected]ca13d804c2009-05-14 04:28:07741 // Invoked when a key is pressed before the key event is processed (and
742 // potentially eaten) by the focus manager for tab traversal, accelerators and
743 // other focus related actions.
744 // The default implementation returns false, ensuring that tab traversal and
745 // accelerators processing is performed.
746 // Subclasses should return true if they want to process the key event and not
747 // have it processed as an accelerator (if any) or as a tab traversal (if the
748 // key event is for the TAB key). In that case, OnKeyPressed will
749 // subsequently be invoked for that event.
750 virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& e) {
751 return false;
752 }
753
initial.commit09911bf2008-07-26 23:55:29754 // Invoked when a key is pressed or released.
755 // Subclasser should return true if the event has been processed and false
756 // otherwise. If the event has not been processed, the parent will be given a
757 // chance.
758 virtual bool OnKeyPressed(const KeyEvent& e);
759 virtual bool OnKeyReleased(const KeyEvent& e);
760
initial.commit09911bf2008-07-26 23:55:29761 // Invoked when the user uses the mousewheel. Implementors should return true
762 // if the event has been processed and false otherwise. This message is sent
763 // if the view is focused. If the event has not been processed, the parent
764 // will be given a chance.
765 virtual bool OnMouseWheel(const MouseWheelEvent& e);
766
767 // Drag and drop functions.
768
769 // Set/get the DragController. See description of DragController for more
770 // information.
771 void SetDragController(DragController* drag_controller);
772 DragController* GetDragController();
773
774 // During a drag and drop session when the mouse moves the view under the
[email protected]134c47b92009-08-19 03:33:44775 // mouse is queried for the drop types it supports by way of the
776 // GetDropFormats methods. If the view returns true and the drag site can
777 // provide data in one of the formats, the view is asked if the drop data
778 // is required before any other drop events are sent. Once the
779 // data is available the view is asked if it supports the drop (by way of
780 // the CanDrop method). If a view returns true from CanDrop,
initial.commit09911bf2008-07-26 23:55:29781 // OnDragEntered is sent to the view when the mouse first enters the view,
782 // as the mouse moves around within the view OnDragUpdated is invoked.
783 // If the user releases the mouse over the view and OnDragUpdated returns a
784 // valid drop, then OnPerformDrop is invoked. If the mouse moves outside the
785 // view or over another view that wants the drag, OnDragExited is invoked.
786 //
787 // Similar to mouse events, the deepest view under the mouse is first checked
788 // if it supports the drop (Drop). If the deepest view under
789 // the mouse does not support the drop, the ancestors are walked until one
790 // is found that supports the drop.
791
[email protected]134c47b92009-08-19 03:33:44792 // Override and return the set of formats that can be dropped on this view.
793 // |formats| is a bitmask of the formats defined bye OSExchangeData::Format.
794 // The default implementation returns false, which means the view doesn't
795 // support dropping.
796 virtual bool GetDropFormats(
797 int* formats,
798 std::set<OSExchangeData::CustomFormat>* custom_formats);
799
800 // Override and return true if the data must be available before any drop
801 // methods should be invoked. The default is false.
802 virtual bool AreDropTypesRequired();
803
initial.commit09911bf2008-07-26 23:55:29804 // A view that supports drag and drop must override this and return true if
805 // data contains a type that may be dropped on this view.
806 virtual bool CanDrop(const OSExchangeData& data);
807
808 // OnDragEntered is invoked when the mouse enters this view during a drag and
809 // drop session and CanDrop returns true. This is immediately
810 // followed by an invocation of OnDragUpdated, and eventually one of
811 // OnDragExited or OnPerformDrop.
812 virtual void OnDragEntered(const DropTargetEvent& event);
813
814 // Invoked during a drag and drop session while the mouse is over the view.
815 // This should return a bitmask of the DragDropTypes::DragOperation supported
816 // based on the location of the event. Return 0 to indicate the drop should
817 // not be accepted.
818 virtual int OnDragUpdated(const DropTargetEvent& event);
819
820 // Invoked during a drag and drop session when the mouse exits the views, or
821 // when the drag session was canceled and the mouse was over the view.
822 virtual void OnDragExited();
823
824 // Invoked during a drag and drop session when OnDragUpdated returns a valid
825 // operation and the user release the mouse.
826 virtual int OnPerformDrop(const DropTargetEvent& event);
827
828 // Returns true if the mouse was dragged enough to start a drag operation.
829 // delta_x and y are the distance the mouse was dragged.
830 static bool ExceededDragThreshold(int delta_x, int delta_y);
831
832 // This method is the main entry point to process paint for this
833 // view and its children. This method is called by the painting
834 // system. You should call this only if you want to draw a sub tree
835 // inside a custom graphics.
836 // To customize painting override either the Paint or PaintChildren method,
837 // not this one.
[email protected]82522512009-05-15 07:37:29838 virtual void ProcessPaint(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29839
840 // Paint the View's child Views, in reverse order.
[email protected]82522512009-05-15 07:37:29841 virtual void PaintChildren(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29842
843 // Sets the ContextMenuController. Setting this to non-null makes the View
844 // process mouse events.
845 void SetContextMenuController(ContextMenuController* menu_controller);
846 ContextMenuController* GetContextMenuController() {
847 return context_menu_controller_;
848 }
849
[email protected]042811c2008-10-31 21:31:34850 // Provides default implementation for context menu handling. The default
851 // implementation calls the ShowContextMenu of the current
852 // ContextMenuController (if it is not NULL). Overridden in subclassed views
853 // to provide right-click menu display triggerd by the keyboard (i.e. for the
854 // Chrome toolbar Back and Forward buttons). No source needs to be specified,
855 // as it is always equal to the current View.
[email protected]e9adf0702010-03-08 23:34:07856 virtual void ShowContextMenu(const gfx::Point& p,
[email protected]042811c2008-10-31 21:31:34857 bool is_mouse_gesture);
858
[email protected]9a3f0ac22008-11-14 03:24:02859 // The background object is owned by this object and may be NULL.
860 void set_background(Background* b) { background_.reset(b); }
861 const Background* background() const { return background_.get(); }
initial.commit09911bf2008-07-26 23:55:29862
[email protected]9a3f0ac22008-11-14 03:24:02863 // The border object is owned by this object and may be NULL.
864 void set_border(Border* b) { border_.reset(b); }
865 const Border* border() const { return border_.get(); }
initial.commit09911bf2008-07-26 23:55:29866
867 // Returns the insets of the current border. If there is no border an empty
868 // insets is returned.
[email protected]a37bea82009-04-22 23:02:15869 virtual gfx::Insets GetInsets() const;
initial.commit09911bf2008-07-26 23:55:29870
871 // Return the cursor that should be used for this view or NULL if
872 // the default cursor should be used. The provided point is in the
[email protected]9abf8dd62009-06-04 06:40:42873 // receiver's coordinate system. The caller is responsible for managing the
874 // lifetime of the returned object, though that lifetime may vary from
875 // platform to platform. On Windows, the cursor is a shared resource but in
876 // Gtk, the framework destroys the returned cursor after setting it.
877 virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type,
[email protected]e9adf0702010-03-08 23:34:07878 const gfx::Point& p);
initial.commit09911bf2008-07-26 23:55:29879
880 // Convenience to test whether a point is within this view's bounds
[email protected]613b8062008-10-14 23:45:09881 virtual bool HitTest(const gfx::Point& l) const;
initial.commit09911bf2008-07-26 23:55:29882
883 // Gets the tooltip for this View. If the View does not have a tooltip,
884 // return false. If the View does have a tooltip, copy the tooltip into
885 // the supplied string and return true.
886 // Any time the tooltip text that a View is displaying changes, it must
887 // invoke TooltipTextChanged.
[email protected]e9adf0702010-03-08 23:34:07888 // |p| provides the coordinates of the mouse (relative to this view).
889 virtual bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip);
initial.commit09911bf2008-07-26 23:55:29890
891 // Returns the location (relative to this View) for the text on the tooltip
892 // to display. If false is returned (the default), the tooltip is placed at
893 // a default position.
[email protected]e9adf0702010-03-08 23:34:07894 virtual bool GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* loc);
initial.commit09911bf2008-07-26 23:55:29895
896 // Set whether this view is owned by its parent. A view that is owned by its
897 // parent is automatically deleted when the parent is deleted. The default is
898 // true. Set to false if the view is owned by another object and should not
899 // be deleted by its parent.
[email protected]09fe9492009-11-07 02:23:06900 void set_parent_owned(bool is_parent_owned) {
901 is_parent_owned_ = is_parent_owned;
902 }
initial.commit09911bf2008-07-26 23:55:29903
[email protected]09fe9492009-11-07 02:23:06904 // Return whether a view is owned by its parent.
905 bool IsParentOwned() const { return is_parent_owned_; }
initial.commit09911bf2008-07-26 23:55:29906
907 // Return the receiving view's class name. A view class is a string which
908 // uniquely identifies the view class. It is intended to be used as a way to
909 // find out during run time if a view can be safely casted to a specific view
910 // subclass. The default implementation returns kViewClassName.
911 virtual std::string GetClassName() const;
912
[email protected]5c2b98b2009-03-09 20:55:54913 // Returns the first ancestor, starting at this, whose class name is |name|.
914 // Returns null if no ancestor has the class name |name|.
915 View* GetAncestorWithClassName(const std::string& name);
916
initial.commit09911bf2008-07-26 23:55:29917 // Returns the visible bounds of the receiver in the receivers coordinate
918 // system.
919 //
920 // When traversing the View hierarchy in order to compute the bounds, the
921 // function takes into account the mirroring setting for each View and
922 // therefore it will return the mirrored version of the visible bounds if
923 // need be.
924 gfx::Rect GetVisibleBounds();
925
926 // Subclasses that contain traversable children that are not directly
927 // accessible through the children hierarchy should return the associated
928 // FocusTraversable for the focus traversal to work properly.
929 virtual FocusTraversable* GetFocusTraversable() { return NULL; }
930
[email protected]83548a42010-06-18 13:53:37931 // Subclasses that can act as a "pane" must implement their own
932 // FocusTraversable to keep the focus trapped within the pane.
933 // If this method returns an object, any view that's a direct or
934 // indirect child of this view will always use this FocusTraversable
935 // rather than the one from the widget.
936 virtual FocusTraversable* GetPaneFocusTraversable() { return NULL; }
937
initial.commit09911bf2008-07-26 23:55:29938#ifndef NDEBUG
939 // Debug method that logs the view hierarchy to the output.
940 void PrintViewHierarchy();
941
942 // Debug method that logs the focus traversal hierarchy to the output.
943 void PrintFocusHierarchy();
944#endif
945
946 // The following methods are used by ScrollView to determine the amount
947 // to scroll relative to the visible bounds of the view. For example, a
948 // return value of 10 indicates the scrollview should scroll 10 pixels in
949 // the appropriate direction.
950 //
951 // Each method takes the following parameters:
952 //
953 // is_horizontal: if true, scrolling is along the horizontal axis, otherwise
954 // the vertical axis.
955 // is_positive: if true, scrolling is by a positive amount. Along the
956 // vertical axis scrolling by a positive amount equates to
957 // scrolling down.
958 //
959 // The return value should always be positive and gives the number of pixels
960 // to scroll. ScrollView interprets a return value of 0 (or negative)
961 // to scroll by a default amount.
962 //
963 // See VariableRowHeightScrollHelper and FixedRowHeightScrollHelper for
964 // implementations of common cases.
965 virtual int GetPageScrollIncrement(ScrollView* scroll_view,
966 bool is_horizontal, bool is_positive);
967 virtual int GetLineScrollIncrement(ScrollView* scroll_view,
968 bool is_horizontal, bool is_positive);
969
[email protected]4a190632009-05-09 01:07:42970 // Get the theme provider from the parent widget.
[email protected]45da6c72009-10-28 20:45:42971 ThemeProvider* GetThemeProvider() const;
[email protected]4a190632009-05-09 01:07:42972
initial.commit09911bf2008-07-26 23:55:29973 protected:
[email protected]59461d22010-07-21 15:41:09974 // Returns whether this view can accept focus.
975 // A view can accept focus if it's enabled, focusable and visible.
976 // This method is intended for views to use when calculating preferred size.
977 // The FocusManager and other places use IsFocusableInRootView.
978 virtual bool IsFocusable() const;
initial.commit09911bf2008-07-26 23:55:29979
[email protected]32670b02009-03-03 00:28:00980 // Called when the UI theme has changed, overriding allows individual Views to
981 // do special cleanup and processing (such as dropping resource caches).
[email protected]8b9a8f12010-07-27 01:39:13982 // To dispatch a theme changed notification, call
983 // RootView::NotifyThemeChanged().
984 virtual void OnThemeChanged() { }
[email protected]32670b02009-03-03 00:28:00985
[email protected]b2b718012010-03-25 15:09:06986 // Called when the locale has changed, overriding allows individual Views to
[email protected]7ceeba72010-04-20 18:22:12987 // update locale-dependent strings.
[email protected]8b9a8f12010-07-27 01:39:13988 // To dispatch a locale changed notification, call
989 // RootView::NotifyLocaleChanged().
990 virtual void OnLocaleChanged() { }
[email protected]b2b718012010-03-25 15:09:06991
initial.commit09911bf2008-07-26 23:55:29992#ifndef NDEBUG
993 // Returns true if the View is currently processing a paint.
994 virtual bool IsProcessingPaint() const;
995#endif
996
[email protected]f704ee72008-11-10 21:31:59997 // Returns the location, in screen coordinates, to show the context menu at
998 // when the context menu is shown from the keyboard. This implementation
999 // returns the middle of the visible region of this view.
1000 //
1001 // This method is invoked when the context menu is shown by way of the
1002 // keyboard.
1003 virtual gfx::Point GetKeyboardContextMenuLocation();
1004
[email protected]82739cf2008-09-16 00:37:561005 // Called by HitTest to see if this View has a custom hit test mask. If the
1006 // return value is true, GetHitTestMask will be called to obtain the mask.
1007 // Default value is false, in which case the View will hit-test against its
1008 // bounds.
1009 virtual bool HasHitTestMask() const;
1010
1011 // Called by HitTest to retrieve a mask for hit-testing against. Subclasses
1012 // override to provide custom shaped hit test regions.
1013 virtual void GetHitTestMask(gfx::Path* mask) const;
1014
initial.commit09911bf2008-07-26 23:55:291015 // This method is invoked when the tree changes.
1016 //
1017 // When a view is removed, it is invoked for all children and grand
1018 // children. For each of these views, a notification is sent to the
1019 // view and all parents.
1020 //
1021 // When a view is added, a notification is sent to the view, all its
1022 // parents, and all its children (and grand children)
1023 //
1024 // Default implementation does nothing. Override to perform operations
1025 // required when a view is added or removed from a view hierarchy
1026 //
1027 // parent is the new or old parent. Child is the view being added or
1028 // removed.
1029 //
1030 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
1031
1032 // When SetVisible() changes the visibility of a view, this method is
1033 // invoked for that view as well as all the children recursively.
1034 virtual void VisibilityChanged(View* starting_from, bool is_visible);
1035
[email protected]bda9556c2010-01-07 00:55:161036 // Called when the native view hierarchy changed.
1037 // |attached| is true if that view has been attached to a new NativeView
1038 // hierarchy, false if it has been detached.
1039 // |native_view| is the NativeView this view was attached/detached from, and
1040 // |root_view| is the root view associated with the NativeView.
1041 // Views created without a native view parent don't have a focus manager.
1042 // When this function is called they could do the processing that requires
1043 // it - like registering accelerators, for example.
1044 virtual void NativeViewHierarchyChanged(bool attached,
1045 gfx::NativeView native_view,
1046 RootView* root_view);
1047
[email protected]7ccc52b72009-05-08 21:09:111048 // Called when the preferred size of a child view changed. This gives the
1049 // parent an opportunity to do a fresh layout if that makes sense.
1050 virtual void ChildPreferredSizeChanged(View* child) {}
1051
[email protected]9ea053e2010-07-15 08:19:051052 // Invalidates the layout and calls ChildPreferredSizeChanged on the parent
1053 // if there is one. Be sure to call View::PreferredSizeChanged when
1054 // overriding such that the layout is properly invalidated.
[email protected]7ccc52b72009-05-08 21:09:111055 virtual void PreferredSizeChanged();
1056
initial.commit09911bf2008-07-26 23:55:291057 // Views must invoke this when the tooltip text they are to display changes.
1058 void TooltipTextChanged();
1059
initial.commit09911bf2008-07-26 23:55:291060 // Sets whether this view wants notification when its visible bounds relative
1061 // to the root view changes. If true, this view is notified any time the
1062 // origin of one its ancestors changes, or the portion of the bounds not
1063 // obscured by ancestors changes. The default is false.
1064 void SetNotifyWhenVisibleBoundsInRootChanges(bool value);
1065 bool GetNotifyWhenVisibleBoundsInRootChanges();
1066
1067 // Notification that this views visible bounds, relative to the RootView
1068 // has changed. The visible bounds corresponds to the region of the
1069 // view not obscured by other ancestors.
1070 virtual void VisibleBoundsInRootChanged() {}
1071
1072 // Sets the keyboard focus to this View. The correct way to set the focus is
1073 // to call RequestFocus() on the view. This method is called when the focus is
1074 // set and gives an opportunity to subclasses to perform any extra focus steps
1075 // (for example native component set the native focus on their native
1076 // component). The default behavior is to set the native focus on the root
[email protected]a0dde122008-11-21 20:51:201077 // Widget, which is what is appropriate for views that have no native window
1078 // associated with them (so the root view gets the keyboard messages).
initial.commit09911bf2008-07-26 23:55:291079 virtual void Focus();
1080
initial.commit09911bf2008-07-26 23:55:291081 // These are cover methods that invoke the method of the same name on
1082 // the DragController. Subclasses may wish to override rather than install
1083 // a DragController.
1084 // See DragController for a description of these methods.
[email protected]e9adf0702010-03-08 23:34:071085 virtual int GetDragOperations(const gfx::Point& press_pt);
1086 virtual void WriteDragData(const gfx::Point& press_pt, OSExchangeData* data);
initial.commit09911bf2008-07-26 23:55:291087
1088 // Invoked from DoDrag after the drag completes. This implementation does
1089 // nothing, and is intended for subclasses to do cleanup.
1090 virtual void OnDragDone();
1091
1092 // Returns whether we're in the middle of a drag session that was initiated
1093 // by us.
1094 bool InDrag();
1095
[email protected]253a39a2009-05-29 20:45:131096 // Returns how much the mouse needs to move in one direction to start a
1097 // drag. These methods cache in a platform-appropriate way. These values are
1098 // used by the public static method ExceededDragThreshold().
1099 static int GetHorizontalDragThreshold();
1100 static int GetVerticalDragThreshold();
1101
[email protected]59461d22010-07-21 15:41:091102 // The id of this View. Used to find this View.
1103 int id_;
1104
1105 // The group of this view. Some view subclasses use this id to find other
1106 // views of the same group. For example radio button uses this information
1107 // to find other radio buttons.
1108 int group_;
1109
initial.commit09911bf2008-07-26 23:55:291110 // Whether this view is enabled.
1111 bool enabled_;
1112
1113 // Whether the view can be focused.
1114 bool focusable_;
1115
[email protected]83548a42010-06-18 13:53:371116 // Whether this view is focusable if the user requires full keyboard access,
1117 // even though it may not be normally focusable.
1118 bool accessibility_focusable_;
1119
initial.commit09911bf2008-07-26 23:55:291120 private:
1121 friend class RootView;
1122 friend class FocusManager;
1123 friend class ViewStorage;
1124
1125 // Used to track a drag. RootView passes this into
1126 // ProcessMousePressed/Dragged.
1127 struct DragInfo {
1128 // Sets possible_drag to false and start_x/y to 0. This is invoked by
1129 // RootView prior to invoke ProcessMousePressed.
1130 void Reset();
1131
[email protected]e9adf0702010-03-08 23:34:071132 // Sets possible_drag to true and start_pt to the specified point.
initial.commit09911bf2008-07-26 23:55:291133 // This is invoked by the target view if it detects the press may generate
1134 // a drag.
[email protected]e9adf0702010-03-08 23:34:071135 void PossibleDrag(const gfx::Point& p);
initial.commit09911bf2008-07-26 23:55:291136
1137 // Whether the press may generate a drag.
1138 bool possible_drag;
1139
1140 // Coordinates of the mouse press.
[email protected]e9adf0702010-03-08 23:34:071141 gfx::Point start_pt;
initial.commit09911bf2008-07-26 23:55:291142 };
1143
[email protected]8b9a8f12010-07-27 01:39:131144 // Used to propagate theme changed notifications from the root view to all
1145 // views in the hierarchy.
1146 virtual void PropagateThemeChanged();
1147
1148 // Used to propagate locale changed notifications from the root view to all
1149 // views in the hierarchy.
1150 virtual void PropagateLocaleChanged();
[email protected]7ceeba72010-04-20 18:22:121151
initial.commit09911bf2008-07-26 23:55:291152 // RootView invokes these. These in turn invoke the appropriate OnMouseXXX
1153 // method. If a drag is detected, DoDrag is invoked.
1154 bool ProcessMousePressed(const MouseEvent& e, DragInfo* drop_info);
1155 bool ProcessMouseDragged(const MouseEvent& e, DragInfo* drop_info);
1156 void ProcessMouseReleased(const MouseEvent& e, bool canceled);
1157
[email protected]ad84c8f2010-09-08 14:06:101158#if defined(TOUCH_UI)
1159 // RootView will invoke this with incoming TouchEvents. Returns the
1160 // the result of OnTouchEvent: true if the event was handled by the
1161 // callee.
1162 bool ProcessTouchEvent(const TouchEvent& e);
1163#endif
1164
initial.commit09911bf2008-07-26 23:55:291165 // Starts a drag and drop operation originating from this view. This invokes
1166 // WriteDragData to write the data and GetDragOperations to determine the
1167 // supported drag operations. When done, OnDragDone is invoked.
[email protected]e9adf0702010-03-08 23:34:071168 void DoDrag(const MouseEvent& e, const gfx::Point& press_pt);
initial.commit09911bf2008-07-26 23:55:291169
initial.commit09911bf2008-07-26 23:55:291170 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true,
1171 // the next and previous focusable views of views pointing to this view are
1172 // updated. If |update_tool_tip| is true, the tooltip is updated. If
1173 // |delete_removed_view| is true, the view is also deleted (if it is parent
1174 // owned).
1175 void DoRemoveChildView(View* view,
1176 bool update_focus_cycle,
1177 bool update_tool_tip,
1178 bool delete_removed_view);
1179
1180 // Sets the parent View. This is called automatically by AddChild and is
1181 // thus private.
[email protected]054e3fd2009-09-14 19:48:051182 void SetParent(View* parent);
initial.commit09911bf2008-07-26 23:55:291183
1184 // Call ViewHierarchyChanged for all child views on all parents
1185 void PropagateRemoveNotifications(View* parent);
1186
1187 // Call ViewHierarchyChanged for all children
1188 void PropagateAddNotifications(View* parent, View* child);
1189
1190 // Call VisibilityChanged() recursively for all children.
1191 void PropagateVisibilityNotifications(View* from, bool is_visible);
1192
[email protected]bda9556c2010-01-07 00:55:161193 // Propagates NativeViewHierarchyChanged() notification through all the
1194 // children.
1195 void PropagateNativeViewHierarchyChanged(bool attached,
1196 gfx::NativeView native_view,
1197 RootView* root_view);
1198
initial.commit09911bf2008-07-26 23:55:291199 // Takes care of registering/unregistering accelerators if
1200 // |register_accelerators| true and calls ViewHierarchyChanged().
1201 void ViewHierarchyChangedImpl(bool register_accelerators,
[email protected]bb515ed2009-01-15 00:53:431202 bool is_add,
1203 View* parent,
1204 View* child);
initial.commit09911bf2008-07-26 23:55:291205
1206 // This is the actual implementation for ConvertPointToView()
1207 // Attempts a parent -> child conversion and then a
1208 // child -> parent conversion if try_other_direction is true
[email protected]bb515ed2009-01-15 00:53:431209 static void ConvertPointToView(const View* src,
1210 const View* dst,
initial.commit09911bf2008-07-26 23:55:291211 gfx::Point* point,
1212 bool try_other_direction);
1213
[email protected]a0dde122008-11-21 20:51:201214 // Propagates UpdateTooltip() to the TooltipManager for the Widget.
initial.commit09911bf2008-07-26 23:55:291215 // This must be invoked any time the View hierarchy changes in such a way
1216 // the view under the mouse differs. For example, if the bounds of a View is
1217 // changed, this is invoked. Similarly, as Views are added/removed, this
1218 // is invoked.
1219 void UpdateTooltip();
1220
1221 // Recursively descends through all descendant views,
1222 // registering/unregistering all views that want visible bounds in root
[email protected]9fc4f202010-07-07 15:38:191223 // view notification.
1224 static void RegisterChildrenForVisibleBoundsNotification(RootView* root,
1225 View* view);
1226 static void UnregisterChildrenForVisibleBoundsNotification(RootView* root,
1227 View* view);
initial.commit09911bf2008-07-26 23:55:291228
1229 // Adds/removes view to the list of descendants that are notified any time
1230 // this views location and possibly size are changed.
1231 void AddDescendantToNotify(View* view);
1232 void RemoveDescendantToNotify(View* view);
1233
1234 // Initialize the previous/next focusable views of the specified view relative
1235 // to the view at the specified index.
1236 void InitFocusSiblings(View* view, int index);
1237
1238 // Actual implementation of PrintFocusHierarchy.
1239 void PrintViewHierarchyImp(int indent);
1240 void PrintFocusHierarchyImp(int indent);
1241
[email protected]71421c3f2009-06-06 00:41:441242 // Registers this view's keyboard accelerators that are not registered to
1243 // FocusManager yet, if possible.
1244 void RegisterPendingAccelerators();
1245
1246 // Unregisters all the keyboard accelerators associated with this view.
[email protected]bda9556c2010-01-07 00:55:161247 // |leave_data_intact| if true does not remove data from accelerators_ array,
1248 // so it could be re-registered with other focus manager
1249 void UnregisterAccelerators(bool leave_data_intact);
initial.commit09911bf2008-07-26 23:55:291250
[email protected]80f8b9f2008-10-16 18:17:471251 // This View's bounds in the parent coordinate system.
1252 gfx::Rect bounds_;
1253
[email protected]9ea053e2010-07-15 08:19:051254 // Whether the view needs to be laid out.
1255 bool needs_layout_;
1256
initial.commit09911bf2008-07-26 23:55:291257 // This view's parent
[email protected]054e3fd2009-09-14 19:48:051258 View* parent_;
initial.commit09911bf2008-07-26 23:55:291259
1260 // This view's children.
1261 typedef std::vector<View*> ViewList;
1262 ViewList child_views_;
1263
initial.commit09911bf2008-07-26 23:55:291264 // The View's LayoutManager defines the sizing heuristics applied to child
1265 // Views. The default is absolute positioning according to bounds_.
1266 scoped_ptr<LayoutManager> layout_manager_;
1267
1268 // Visible state
1269 bool is_visible_;
1270
1271 // Background
[email protected]9a3f0ac22008-11-14 03:24:021272 scoped_ptr<Background> background_;
initial.commit09911bf2008-07-26 23:55:291273
1274 // Border.
[email protected]9a3f0ac22008-11-14 03:24:021275 scoped_ptr<Border> border_;
initial.commit09911bf2008-07-26 23:55:291276
1277 // Whether this view is owned by its parent.
1278 bool is_parent_owned_;
1279
1280 // See SetNotifyWhenVisibleBoundsInRootChanges.
1281 bool notify_when_visible_bounds_in_root_changes_;
1282
1283 // Whether or not RegisterViewForVisibleBoundsNotification on the RootView
1284 // has been invoked.
1285 bool registered_for_visible_bounds_notification_;
1286
[email protected]bda9556c2010-01-07 00:55:161287 // true if when we were added to hierarchy we were without focus manager
1288 // attempt addition when ancestor chain changed.
1289 bool accelerator_registration_delayed_;
1290
initial.commit09911bf2008-07-26 23:55:291291 // List of descendants wanting notification when their visible bounds change.
1292 scoped_ptr<ViewList> descendants_to_notify_;
1293
[email protected]d5c81012010-04-03 00:56:121294 // Name for this view, which can be retrieved by accessibility APIs.
1295 std::wstring accessible_name_;
1296
initial.commit09911bf2008-07-26 23:55:291297 // Next view to be focused when the Tab key is pressed.
1298 View* next_focusable_view_;
1299
1300 // Next view to be focused when the Shift-Tab key combination is pressed.
1301 View* previous_focusable_view_;
1302
[email protected]bda9556c2010-01-07 00:55:161303 // Focus manager accelerators registered on.
1304 FocusManager* accelerator_focus_manager_;
1305
[email protected]71421c3f2009-06-06 00:41:441306 // The list of accelerators. List elements in the range
1307 // [0, registered_accelerator_count_) are already registered to FocusManager,
1308 // and the rest are not yet.
[email protected]1eb89e82008-08-15 12:27:031309 scoped_ptr<std::vector<Accelerator> > accelerators_;
[email protected]4bd23f32009-06-08 20:59:191310 size_t registered_accelerator_count_;
initial.commit09911bf2008-07-26 23:55:291311
initial.commit09911bf2008-07-26 23:55:291312 // The menu controller.
1313 ContextMenuController* context_menu_controller_;
1314
[email protected]6ff244f2009-01-20 20:38:081315#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291316 // The accessibility implementation for this View.
[email protected]5fe15722010-10-22 00:03:221317 scoped_refptr<ViewAccessibility> view_accessibility_;
[email protected]6ff244f2009-01-20 20:38:081318#endif
initial.commit09911bf2008-07-26 23:55:291319
1320 DragController* drag_controller_;
1321
[email protected]82522512009-05-15 07:37:291322 // Indicates whether or not the gfx::Canvas object passed to View::Paint()
initial.commit09911bf2008-07-26 23:55:291323 // is going to be flipped horizontally (using the appropriate transform) on
1324 // right-to-left locales for this View.
1325 bool flip_canvas_on_paint_for_rtl_ui_;
1326
[email protected]8af4c1992010-02-04 21:38:071327 // The default value for how long to wait (in ms) before showing a menu
1328 // button on hover. This value is used if the OS doesn't supply one.
1329 static const int kShowFolderDropMenuDelay;
1330
[email protected]1eb89e82008-08-15 12:27:031331 DISALLOW_COPY_AND_ASSIGN(View);
initial.commit09911bf2008-07-26 23:55:291332};
1333
[email protected]c2dacc92008-10-16 23:51:381334} // namespace views
initial.commit09911bf2008-07-26 23:55:291335
[email protected]2362e4f2009-05-08 00:34:051336#endif // VIEWS_VIEW_H_