blob: 764cbd3e858052e451bd08ff3cbf831029c34e63 [file] [log] [blame]
[email protected]5a3b9142009-08-28 21:03:171// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2362e4f2009-05-08 00:34:055#ifndef VIEWS_VIEW_H_
6#define VIEWS_VIEW_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]8c117712009-01-13 12:26:468#include "build/build_config.h"
9
[email protected]1bc83062009-02-06 00:16:3710#include <algorithm>
initial.commit09911bf2008-07-26 23:55:2911#include <map>
[email protected]134c47b92009-08-19 03:33:4412#include <set>
[email protected]1bc83062009-02-06 00:16:3713#include <string>
initial.commit09911bf2008-07-26 23:55:2914#include <vector>
15
[email protected]134c47b92009-08-19 03:33:4416#include "app/os_exchange_data.h"
[email protected]9abf8dd62009-06-04 06:40:4217#include "base/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2918#include "base/gfx/rect.h"
19#include "base/scoped_ptr.h"
[email protected]2362e4f2009-05-08 00:34:0520#include "views/accelerator.h"
[email protected]91e81ae2009-05-08 22:14:3821#include "views/accessibility/accessibility_types.h"
[email protected]2362e4f2009-05-08 00:34:0522#include "views/background.h"
23#include "views/border.h"
initial.commit09911bf2008-07-26 23:55:2924
[email protected]1eb89e82008-08-15 12:27:0325namespace gfx {
[email protected]82522512009-05-15 07:37:2926class Canvas;
[email protected]1eb89e82008-08-15 12:27:0327class Insets;
[email protected]82739cf2008-09-16 00:37:5628class Path;
[email protected]1eb89e82008-08-15 12:27:0329}
30
[email protected]fef10642009-03-17 21:17:0431class ViewAccessibilityWrapper;
[email protected]4a190632009-05-09 01:07:4232class ThemeProvider;
initial.commit09911bf2008-07-26 23:55:2933
[email protected]c2dacc92008-10-16 23:51:3834namespace views {
initial.commit09911bf2008-07-26 23:55:2935
36class Background;
37class Border;
38class FocusManager;
39class FocusTraversable;
40class LayoutManager;
41class RestoreFocusTask;
42class RootView;
43class ScrollView;
[email protected]a0dde122008-11-21 20:51:2044class Widget;
[email protected]cd8c47902009-04-30 20:55:3545class Window;
initial.commit09911bf2008-07-26 23:55:2946
47// ContextMenuController is responsible for showing the context menu for a
48// View. To use a ContextMenuController invoke SetContextMenuController on a
49// View. When the appropriate user gesture occurs ShowContextMenu is invoked
50// on the ContextMenuController.
51//
52// Setting a ContextMenuController on a view makes the view process mouse
53// events.
54//
55// It is up to subclasses that do their own mouse processing to invoke
56// the appropriate ContextMenuController method, typically by invoking super's
57// implementation for mouse processing.
58//
59class ContextMenuController {
60 public:
61 // Invoked to show the context menu for the source view. If is_mouse_gesture
62 // is true, the x/y coordinate are the location of the mouse. If
63 // is_mouse_gesture is false, this method was not invoked by a mouse gesture
64 // and x/y is the recommended location to show the menu at.
65 //
66 // x/y is in screen coordinates.
67 virtual void ShowContextMenu(View* source,
68 int x,
69 int y,
70 bool is_mouse_gesture) = 0;
71};
72
73// DragController is responsible for writing drag data for a view, as well as
74// supplying the supported drag operations. Use DragController if you don't
75// want to subclass.
76
77class DragController {
78 public:
79 // Writes the data for the drag.
80 virtual void WriteDragData(View* sender,
81 int press_x,
82 int press_y,
83 OSExchangeData* data) = 0;
84
85 // Returns the supported drag operations (see DragDropTypes for possible
86 // values). A drag is only started if this returns a non-zero value.
87 virtual int GetDragOperations(View* sender, int x, int y) = 0;
88};
89
90
91/////////////////////////////////////////////////////////////////////////////
92//
93// View class
94//
[email protected]c2dacc92008-10-16 23:51:3895// A View is a rectangle within the views View hierarchy. It is the base
[email protected]1bc83062009-02-06 00:16:3796// class for all Views.
initial.commit09911bf2008-07-26 23:55:2997//
98// A View is a container of other Views (there is no such thing as a Leaf
99// View - makes code simpler, reduces type conversion headaches, design
100// mistakes etc)
101//
102// The View contains basic properties for sizing (bounds), layout (flex,
103// orientation, etc), painting of children and event dispatch.
104//
105// The View also uses a simple Box Layout Manager similar to XUL's
106// SprocketLayout system. Alternative Layout Managers implementing the
107// LayoutManager interface can be used to lay out children if required.
108//
109// It is up to the subclass to implement Painting and storage of subclass -
110// specific properties and functionality.
111//
112/////////////////////////////////////////////////////////////////////////////
113class View : public AcceleratorTarget {
114 public:
[email protected]6f3bb6c2008-09-17 22:25:33115 // Used in the versions of GetBounds() and x() that take a transformation
initial.commit09911bf2008-07-26 23:55:29116 // parameter in order to determine whether or not to take into account the
117 // mirroring setting of the View when returning bounds positions.
118 enum PositionMirroringSettings {
119 IGNORE_MIRRORING_TRANSFORMATION = 0,
120 APPLY_MIRRORING_TRANSFORMATION
121 };
122
123 // The view class name.
124 static char kViewClassName[];
125
126 View();
127 virtual ~View();
128
129 // Sizing functions
130
131 // Get the bounds of the View, relative to the parent. Essentially, this
132 // function returns the bounds_ rectangle.
133 //
134 // This is the function subclasses should use whenever they need to obtain
135 // the bounds of one of their child views (for example, when implementing
136 // View::Layout()).
[email protected]24db2eb2009-07-17 17:54:16137 const gfx::Rect& bounds() const { return bounds_; }
[email protected]80f8b9f2008-10-16 18:17:47138
139 // Get the size of the View.
[email protected]24db2eb2009-07-17 17:54:16140 const gfx::Size& size() const { return bounds_.size(); }
initial.commit09911bf2008-07-26 23:55:29141
142 // Return the bounds of the View, relative to the parent. If
143 // |settings| is IGNORE_MIRRORING_TRANSFORMATION, the function returns the
144 // bounds_ rectangle. If |settings| is APPLY_MIRRORING_SETTINGS AND the
145 // parent View is using a right-to-left UI layout, then the function returns
146 // a shifted version of the bounds_ rectangle that represents the mirrored
147 // View bounds.
148 //
149 // NOTE: in the vast majority of the cases, the mirroring implementation is
150 // transparent to the View subclasses and therefore you should use the
151 // version of GetBounds() which does not take a transformation settings
152 // parameter.
[email protected]0d8ea702008-10-14 17:03:07153 gfx::Rect GetBounds(PositionMirroringSettings settings) const;
initial.commit09911bf2008-07-26 23:55:29154
155 // Set the bounds in the parent's coordinate system.
[email protected]80f8b9f2008-10-16 18:17:47156 void SetBounds(const gfx::Rect& bounds);
157 void SetBounds(int x, int y, int width, int height) {
158 SetBounds(gfx::Rect(x, y, std::max(0, width), std::max(0, height)));
159 }
[email protected]6f3bb6c2008-09-17 22:25:33160 void SetX(int x) { SetBounds(x, y(), width(), height()); }
161 void SetY(int y) { SetBounds(x(), y, width(), height()); }
initial.commit09911bf2008-07-26 23:55:29162
163 // Returns the left coordinate of the View, relative to the parent View,
[email protected]80f8b9f2008-10-16 18:17:47164 // which is the value of bounds_.x().
initial.commit09911bf2008-07-26 23:55:29165 //
166 // This is the function subclasses should use whenever they need to obtain
167 // the left position of one of their child views (for example, when
168 // implementing View::Layout()).
[email protected]0a1d36b22008-10-17 19:33:09169 // This is equivalent to GetX(IGNORE_MIRRORING_TRANSFORMATION), but
170 // inlinable.
171 int x() const { return bounds_.x(); }
172 int y() const { return bounds_.y(); }
173 int width() const { return bounds_.width(); }
174 int height() const { return bounds_.height(); }
initial.commit09911bf2008-07-26 23:55:29175
176 // Return the left coordinate of the View, relative to the parent. If
177 // |settings| is IGNORE_MIRRORING_SETTINGS, the function returns the value of
[email protected]80f8b9f2008-10-16 18:17:47178 // bounds_.x(). If |settings| is APPLY_MIRRORING_SETTINGS AND the parent
initial.commit09911bf2008-07-26 23:55:29179 // View is using a right-to-left UI layout, then the function returns the
[email protected]80f8b9f2008-10-16 18:17:47180 // mirrored value of bounds_.x().
initial.commit09911bf2008-07-26 23:55:29181 //
182 // NOTE: in the vast majority of the cases, the mirroring implementation is
183 // transparent to the View subclasses and therefore you should use the
[email protected]6f3bb6c2008-09-17 22:25:33184 // paremeterless version of x() when you need to get the X
initial.commit09911bf2008-07-26 23:55:29185 // coordinate of a child View.
186 int GetX(PositionMirroringSettings settings) const;
187
initial.commit09911bf2008-07-26 23:55:29188 // Return this control local bounds. If include_border is true, local bounds
[email protected]6f3bb6c2008-09-17 22:25:33189 // is the rectangle {0, 0, width(), height()}, otherwise, it does not
initial.commit09911bf2008-07-26 23:55:29190 // include the area where the border (if any) is painted.
[email protected]80f8b9f2008-10-16 18:17:47191 gfx::Rect GetLocalBounds(bool include_border) const;
initial.commit09911bf2008-07-26 23:55:29192
193 // Get the position of the View, relative to the parent.
194 //
195 // Note that if the parent uses right-to-left UI layout, then the mirrored
[email protected]6f3bb6c2008-09-17 22:25:33196 // position of this View is returned. Use x()/y() if you want to ignore
initial.commit09911bf2008-07-26 23:55:29197 // mirroring.
[email protected]0a1d36b22008-10-17 19:33:09198 gfx::Point GetPosition() const;
initial.commit09911bf2008-07-26 23:55:29199
200 // Get the size the View would like to be, if enough space were available.
[email protected]154f8bc2008-10-15 18:02:30201 virtual gfx::Size GetPreferredSize();
initial.commit09911bf2008-07-26 23:55:29202
203 // Convenience method that sizes this view to its preferred size.
204 void SizeToPreferredSize();
205
206 // Gets the minimum size of the view. View's implementation invokes
207 // GetPreferredSize.
[email protected]154f8bc2008-10-15 18:02:30208 virtual gfx::Size GetMinimumSize();
initial.commit09911bf2008-07-26 23:55:29209
210 // Return the height necessary to display this view with the provided width.
211 // View's implementation returns the value from getPreferredSize.cy.
212 // Override if your View's preferred height depends upon the width (such
213 // as with Labels).
214 virtual int GetHeightForWidth(int w);
215
216 // This method is invoked when this object size or position changes.
217 // The default implementation does nothing.
[email protected]80f8b9f2008-10-16 18:17:47218 virtual void DidChangeBounds(const gfx::Rect& previous,
219 const gfx::Rect& current);
initial.commit09911bf2008-07-26 23:55:29220
221 // Set whether the receiving view is visible. Painting is scheduled as needed
222 virtual void SetVisible(bool flag);
223
224 // Return whether a view is visible
225 virtual bool IsVisible() const { return is_visible_; }
226
227 // Return whether a view and its ancestors are visible. Returns true if the
228 // path from this view to the root view is visible.
229 virtual bool IsVisibleInRootView() const;
230
231 // Set whether this view is enabled. A disabled view does not receive keyboard
232 // or mouse inputs. If flag differs from the current value, SchedulePaint is
233 // invoked.
234 virtual void SetEnabled(bool flag);
235
236 // Returns whether the view is enabled.
237 virtual bool IsEnabled() const;
238
239 // Set whether this view is hottracked. A disabled view cannot be hottracked.
240 // If flag differs from the current value, SchedulePaint is invoked.
241 virtual void SetHotTracked(bool flag);
242
243 // Returns whether the view is hot-tracked.
244 virtual bool IsHotTracked() const { return false; }
245
246 // Returns whether the view is pushed.
247 virtual bool IsPushed() const { return false; }
248
249 // Scrolls the specified region, in this View's coordinate system, to be
250 // visible. View's implementation passes the call onto the parent View (after
251 // adjusting the coordinates). It is up to views that only show a portion of
252 // the child view, such as Viewport, to override appropriately.
253 virtual void ScrollRectToVisible(int x, int y, int width, int height);
254
255 // Layout functions
256
257 // Lay out the child Views (set their bounds based on sizing heuristics
258 // specific to the current Layout Manager)
259 virtual void Layout();
260
261 // Gets/Sets the Layout Manager used by this view to size and place its
262 // children.
263 // The LayoutManager is owned by the View and is deleted when the view is
264 // deleted, or when a new LayoutManager is installed.
265 LayoutManager* GetLayoutManager() const;
266 void SetLayoutManager(LayoutManager* layout);
267
268 // Right-to-left UI layout functions
269
270 // Indicates whether the UI layout for this view is right-to-left. The view
271 // has an RTL UI layout if RTL hasn't been disabled for the view and if the
272 // locale's language is an RTL language.
[email protected]1eb89e82008-08-15 12:27:03273 bool UILayoutIsRightToLeft() const;
initial.commit09911bf2008-07-26 23:55:29274
275 // Enables or disables the right-to-left layout for the view. If |enable| is
276 // true, the layout will become right-to-left only if the locale's language
277 // is right-to-left.
278 //
279 // By default, right-to-left UI layout is enabled for the view and therefore
280 // this function must be called (with false as the |enable| parameter) in
281 // order to disable the right-to-left layout property for a specific instance
282 // of the view. Disabling the right-to-left UI layout is necessary in case a
283 // UI element will not appear correctly when mirrored.
284 void EnableUIMirroringForRTLLanguages(bool enable) {
285 ui_mirroring_is_enabled_for_rtl_languages_ = enable;
286 }
287
[email protected]82522512009-05-15 07:37:29288 // This method determines whether the gfx::Canvas object passed to
initial.commit09911bf2008-07-26 23:55:29289 // View::Paint() needs to be transformed such that anything drawn on the
290 // canvas object during View::Paint() is flipped horizontally.
291 //
292 // By default, this function returns false (which is the initial value of
293 // |flip_canvas_on_paint_for_rtl_ui_|). View subclasses that need to paint on
[email protected]82522512009-05-15 07:37:29294 // a flipped gfx::Canvas when the UI layout is right-to-left need to call
initial.commit09911bf2008-07-26 23:55:29295 // EnableCanvasFlippingForRTLUI().
296 bool FlipCanvasOnPaintForRTLUI() const {
297 return flip_canvas_on_paint_for_rtl_ui_ ? UILayoutIsRightToLeft() : false;
298 }
299
[email protected]82522512009-05-15 07:37:29300 // Enables or disables flipping of the gfx::Canvas during View::Paint().
initial.commit09911bf2008-07-26 23:55:29301 // Note that if canvas flipping is enabled, the canvas will be flipped only
302 // if the UI layout is right-to-left; that is, the canvas will be flipped
303 // only if UILayoutIsRightToLeft() returns true.
304 //
305 // Enabling canvas flipping is useful for leaf views that draw a bitmap that
306 // needs to be flipped horizontally when the UI layout is right-to-left
[email protected]c2dacc92008-10-16 23:51:38307 // (views::Button, for example). This method is helpful for such classes
308 // because their drawing logic stays the same and they can become agnostic to
309 // the UI directionality.
initial.commit09911bf2008-07-26 23:55:29310 void EnableCanvasFlippingForRTLUI(bool enable) {
311 flip_canvas_on_paint_for_rtl_ui_ = enable;
312 }
313
314 // Returns the mirrored X position for the view, relative to the parent. If
315 // the parent view is not mirrored, this function returns bound_.left.
316 //
317 // UI mirroring is transparent to most View subclasses and therefore there is
318 // no need to call this routine from anywhere within your subclass
319 // implementation.
[email protected]63329982008-10-10 21:56:57320 int MirroredX() const;
initial.commit09911bf2008-07-26 23:55:29321
322 // Given a rectangle specified in this View's coordinate system, the function
323 // computes the 'left' value for the mirrored rectangle within this View. If
324 // the View's UI layout is not right-to-left, then bounds.x() is returned.
325 //
326 // UI mirroring is transparent to most View subclasses and therefore there is
327 // no need to call this routine from anywhere within your subclass
328 // implementation.
329 int MirroredLeftPointForRect(const gfx::Rect& rect) const;
330
331 // Given the X coordinate of a point inside the View, this function returns
332 // the mirrored X coordinate of the point if the View's UI layout is
333 // right-to-left. If the layout is left-to-right, the same X coordinate is
334 // returned.
335 //
336 // Following are a few examples of the values returned by this function for
337 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout:
338 //
339 // MirroredXCoordinateInsideView(0) -> 100
340 // MirroredXCoordinateInsideView(20) -> 80
341 // MirroredXCoordinateInsideView(99) -> 1
342 int MirroredXCoordinateInsideView(int x) const {
[email protected]6f3bb6c2008-09-17 22:25:33343 return UILayoutIsRightToLeft() ? width() - x : x;
initial.commit09911bf2008-07-26 23:55:29344 }
345
[email protected]14da3dff2009-06-12 18:01:47346 // Given a X coordinate and a width inside the View, this function returns
347 // the mirrored X coordinate if the View's UI layout is right-to-left. If the
348 // layout is left-to-right, the same X coordinate is returned.
349 //
350 // Following are a few examples of the values returned by this function for
351 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout:
352 //
353 // MirroredXCoordinateInsideView(0, 10) -> 90
354 // MirroredXCoordinateInsideView(20, 20) -> 60
355 int MirroredXWithWidthInsideView(int x, int w) const {
356 return UILayoutIsRightToLeft() ? width() - x - w : x;
357 }
358
initial.commit09911bf2008-07-26 23:55:29359 // Painting functions
360
361 // Mark the specified rectangle as dirty (needing repaint). If |urgent| is
362 // true, the view will be repainted when the current event processing is
363 // done. Otherwise, painting will take place as soon as possible.
[email protected]0a1d36b22008-10-17 19:33:09364 virtual void SchedulePaint(const gfx::Rect& r, bool urgent);
initial.commit09911bf2008-07-26 23:55:29365
366 // Mark the entire View's bounds as dirty. Painting will occur as soon as
367 // possible.
368 virtual void SchedulePaint();
369
370 // Convenience to schedule a paint given some ints. Painting will occur as
371 // soon as possible.
372 virtual void SchedulePaint(int x, int y, int w, int h);
373
374 // Paint the receiving view. g is prepared such as it is in
375 // receiver's coordinate system. g's state is restored after this
376 // call so your implementation can change the graphics configuration
377 //
378 // Default implementation paints the background if it is defined
379 //
380 // Override this method when implementing a new control.
[email protected]82522512009-05-15 07:37:29381 virtual void Paint(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29382
383 // Paint the background if any. This method is called by Paint() and
384 // should rarely be invoked directly.
[email protected]82522512009-05-15 07:37:29385 virtual void PaintBackground(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29386
387 // Paint the border if any. This method is called by Paint() and
388 // should rarely be invoked directly.
[email protected]82522512009-05-15 07:37:29389 virtual void PaintBorder(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29390
391 // Paints the focus border (only if the view has the focus).
392 // This method is called by Paint() and should rarely be invoked directly.
393 // The default implementation paints a gray border around the view. Override
394 // it for custom focus effects.
[email protected]82522512009-05-15 07:37:29395 virtual void PaintFocusBorder(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29396
397 // Paint this View immediately.
398 virtual void PaintNow();
399
initial.commit09911bf2008-07-26 23:55:29400 // Tree functions
401
402 // Add a child View.
403 void AddChildView(View* v);
404
405 // Adds a child View at the specified position.
406 void AddChildView(int index, View* v);
407
408 // Get the child View at the specified index.
409 View* GetChildViewAt(int index) const;
410
411 // Remove a child view from this view. v's parent will change to NULL
412 void RemoveChildView(View *v);
413
414 // Remove all child view from this view. If |delete_views| is true, the views
415 // are deleted, unless marked as not parent owned.
416 void RemoveAllChildViews(bool delete_views);
417
418 // Get the number of child Views.
419 int GetChildViewCount() const;
420
[email protected]24db2eb2009-07-17 17:54:16421 // Returns the deepest descendant that contains the specified point.
[email protected]613b8062008-10-14 23:45:09422 virtual View* GetViewForPoint(const gfx::Point& point);
initial.commit09911bf2008-07-26 23:55:29423
[email protected]a0dde122008-11-21 20:51:20424 // Get the Widget that hosts this View, if any.
425 virtual Widget* GetWidget() const;
initial.commit09911bf2008-07-26 23:55:29426
[email protected]cd8c47902009-04-30 20:55:35427 // Gets the Widget that most closely contains this View, if any.
428 virtual Window* GetWindow() const;
429
initial.commit09911bf2008-07-26 23:55:29430 // Get the containing RootView
431 virtual RootView* GetRootView();
432
433 // Get the parent View
434 View* GetParent() const { return parent_; }
435
436 // Returns the index of the specified |view| in this view's children, or -1
437 // if the specified view is not a child of this view.
438 int GetChildIndex(View* v) const;
439
440 // Returns true if the specified view is a direct or indirect child of this
441 // view.
442 bool IsParentOf(View* v) const;
443
444 // Recursively descends the view tree starting at this view, and returns
445 // the first child that it encounters that has the given ID.
446 // Returns NULL if no matching child view is found.
447 virtual View* GetViewByID(int id) const;
448
449 // Sets and gets the ID for this view. ID should be unique within the subtree
450 // that you intend to search for it. 0 is the default ID for views.
451 void SetID(int id);
452 int GetID() const;
453
454 // A group id is used to tag views which are part of the same logical group.
455 // Focus can be moved between views with the same group using the arrow keys.
456 // Groups are currently used to implement radio button mutual exclusion.
[email protected]96f960d2009-09-14 18:45:30457 // The group id is immutable once it's set.
initial.commit09911bf2008-07-26 23:55:29458 void SetGroup(int gid);
[email protected]96f960d2009-09-14 18:45:30459 // Returns the group id of the view, or -1 if the id is not set yet.
initial.commit09911bf2008-07-26 23:55:29460 int GetGroup() const;
461
462 // If this returns true, the views from the same group can each be focused
463 // when moving focus with the Tab/Shift-Tab key. If this returns false,
464 // only the selected view from the group (obtained with
465 // GetSelectedViewForGroup()) is focused.
466 virtual bool IsGroupFocusTraversable() const { return true; }
467
468 // Fills the provided vector with all the available views which belong to the
469 // provided group.
470 void GetViewsWithGroup(int group_id, std::vector<View*>* out);
471
472 // Return the View that is currently selected in the specified group.
473 // The default implementation simply returns the first View found for that
474 // group.
475 virtual View* GetSelectedViewForGroup(int group_id);
476
477 // Focus support
478 //
479 // Returns the view that should be selected next when pressing Tab.
480 View* GetNextFocusableView();
481
482 // Returns the view that should be selected next when pressing Shift-Tab.
483 View* GetPreviousFocusableView();
484
485 // Sets the component that should be selected next when pressing Tab, and
486 // makes the current view the precedent view of the specified one.
487 // Note that by default views are linked in the order they have been added to
488 // their container. Use this method if you want to modify the order.
489 // IMPORTANT NOTE: loops in the focus hierarchy are not supported.
490 void SetNextFocusableView(View* view);
491
492 // Return whether this view can accept the focus.
493 virtual bool IsFocusable() const;
494
495 // Sets whether this view can accept the focus.
496 // Note that this is false by default so that a view used as a container does
497 // not get the focus.
498 virtual void SetFocusable(bool focusable);
499
500 // Convenience method to retrieve the FocusManager associated with the
[email protected]a0dde122008-11-21 20:51:20501 // Widget that contains this view. This can return NULL if this view is not
502 // part of a view hierarchy with a Widget.
initial.commit09911bf2008-07-26 23:55:29503 virtual FocusManager* GetFocusManager();
504
505 // Sets a keyboard accelerator for that view. When the user presses the
506 // accelerator key combination, the AcceleratorPressed method is invoked.
507 // Note that you can set multiple accelerators for a view by invoking this
508 // method several times.
509 virtual void AddAccelerator(const Accelerator& accelerator);
510
[email protected]e8e0f362008-11-08 01:13:25511 // Removes the specified accelerator for this view.
512 virtual void RemoveAccelerator(const Accelerator& accelerator);
513
initial.commit09911bf2008-07-26 23:55:29514 // Removes all the keyboard accelerators for this view.
515 virtual void ResetAccelerators();
516
517 // Called when a keyboard accelerator is pressed.
518 // Derived classes should implement desired behavior and return true if they
519 // handled the accelerator.
520 virtual bool AcceleratorPressed(const Accelerator& accelerator) {
521 return false;
522 }
523
initial.commit09911bf2008-07-26 23:55:29524 // Returns whether this view currently has the focus.
525 virtual bool HasFocus();
526
527 // Accessibility support
528 // TODO(klink): Move all this out to a AccessibleInfo wrapper class.
529 //
530 // Returns the MSAA default action of the current view. The string returned
531 // describes the default action that will occur when executing
532 // IAccessible::DoDefaultAction. For instance, default action of a button is
533 // 'Press'. Sets the input string appropriately, and returns true if
534 // successful.
535 virtual bool GetAccessibleDefaultAction(std::wstring* action) {
536 return false;
537 }
538
539 // Returns a string containing the mnemonic, or the keyboard shortcut, for a
540 // given control. Sets the input string appropriately, and returns true if
541 // successful.
542 virtual bool GetAccessibleKeyboardShortcut(std::wstring* shortcut) {
543 return false;
544 }
545
546 // Returns a brief, identifying string, containing a unique, readable name of
547 // a given control. Sets the input string appropriately, and returns true if
548 // successful.
549 virtual bool GetAccessibleName(std::wstring* name) { return false; }
550
[email protected]e92070ac2009-04-28 00:12:01551 // Returns the accessibility role of the current view. The role is what
552 // assistive technologies (ATs) use to determine what behavior to expect from
553 // a given control. Sets the input Role appropriately, and returns true if
initial.commit09911bf2008-07-26 23:55:29554 // successful.
[email protected]e92070ac2009-04-28 00:12:01555 virtual bool GetAccessibleRole(AccessibilityTypes::Role* role) {
556 return false;
557 }
initial.commit09911bf2008-07-26 23:55:29558
[email protected]e92070ac2009-04-28 00:12:01559 // Returns the accessibility state of the current view. Sets the input State
560 // appropriately, and returns true if successful.
561 virtual bool GetAccessibleState(AccessibilityTypes::State* state) {
562 return false;
563 }
initial.commit09911bf2008-07-26 23:55:29564
565 // Assigns a keyboard shortcut string description to the given control. Needed
566 // as a View does not know which shortcut will be associated with it until it
567 // is created to be a certain type.
568 virtual void SetAccessibleKeyboardShortcut(const std::wstring& shortcut) {}
569
570 // Assigns a string name to the given control. Needed as a View does not know
571 // which name will be associated with it until it is created to be a
572 // certain type.
573 virtual void SetAccessibleName(const std::wstring& name) {}
574
575 // Returns an instance of a wrapper class implementing the (platform-specific)
576 // accessibility interface for a given View. If one exists, it will be
577 // re-used, otherwise a new instance will be created.
[email protected]fef10642009-03-17 21:17:04578 ViewAccessibilityWrapper* GetViewAccessibilityWrapper();
initial.commit09911bf2008-07-26 23:55:29579
580 // Accessor used to determine if a child view (leaf) has accessibility focus.
581 // Returns NULL if there are no children, or if none of the children has
582 // accessibility focus.
[email protected]c2dacc92008-10-16 23:51:38583 virtual View* GetAccFocusedChildView() { return NULL; }
initial.commit09911bf2008-07-26 23:55:29584
initial.commit09911bf2008-07-26 23:55:29585 // Utility functions
586
587 // Note that the utility coordinate conversions functions always operate on
588 // the mirrored position of the child Views if the parent View uses a
589 // right-to-left UI layout.
590
591 // Convert a point from source coordinate system to dst coordinate system.
592 //
593 // source is a parent or a child of dst, directly or transitively.
594 // If source and dst are not in the same View hierarchy, the result is
595 // undefined.
596 // Source can be NULL in which case it means the screen coordinate system
[email protected]bb515ed2009-01-15 00:53:43597 static void ConvertPointToView(const View* src,
598 const View* dst,
initial.commit09911bf2008-07-26 23:55:29599 gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29600
601 // Convert a point from the coordinate system of a View to that of the
[email protected]a0dde122008-11-21 20:51:20602 // Widget. This is useful for example when sizing HWND children of the
603 // Widget that don't know about the View hierarchy and need to be placed
604 // relative to the Widget that is their parent.
[email protected]2fb6d462009-02-13 18:40:10605 static void ConvertPointToWidget(const View* src, gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29606
[email protected]a0dde122008-11-21 20:51:20607 // Convert a point from a view Widget to a View dest
[email protected]2fb6d462009-02-13 18:40:10608 static void ConvertPointFromWidget(const View* dest, gfx::Point* p);
initial.commit09911bf2008-07-26 23:55:29609
610 // Convert a point from the coordinate system of a View to that of the
611 // screen. This is useful for example when placing popup windows.
[email protected]2fb6d462009-02-13 18:40:10612 static void ConvertPointToScreen(const View* src, gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29613
614 // Event Handlers
615
616 // This method is invoked when the user clicks on this view.
617 // The provided event is in the receiver's coordinate system.
618 //
619 // Return true if you processed the event and want to receive subsequent
620 // MouseDraggged and MouseReleased events. This also stops the event from
621 // bubbling. If you return false, the event will bubble through parent
622 // views.
623 //
624 // If you remove yourself from the tree while processing this, event bubbling
625 // stops as if you returned true, but you will not receive future events.
626 // The return value is ignored in this case.
627 //
628 // Default implementation returns true if a ContextMenuController has been
629 // set, false otherwise. Override as needed.
630 //
631 virtual bool OnMousePressed(const MouseEvent& event);
632
633 // This method is invoked when the user clicked on this control.
634 // and is still moving the mouse with a button pressed.
635 // The provided event is in the receiver's coordinate system.
636 //
637 // Return true if you processed the event and want to receive
638 // subsequent MouseDragged and MouseReleased events.
639 //
640 // Default implementation returns true if a ContextMenuController has been
641 // set, false otherwise. Override as needed.
642 //
643 virtual bool OnMouseDragged(const MouseEvent& event);
644
645 // This method is invoked when the user releases the mouse
646 // button. The event is in the receiver's coordinate system.
647 //
648 // If canceled is true it indicates the mouse press/drag was canceled by a
649 // system/user gesture.
650 //
651 // Default implementation notifies the ContextMenuController is appropriate.
652 // Subclasses that wish to honor the ContextMenuController should invoke
653 // super.
654 virtual void OnMouseReleased(const MouseEvent& event, bool canceled);
655
656 // This method is invoked when the mouse is above this control
657 // The event is in the receiver's coordinate system.
658 //
659 // Default implementation does nothing. Override as needed.
660 virtual void OnMouseMoved(const MouseEvent& e);
661
662 // This method is invoked when the mouse enters this control.
663 //
664 // Default implementation does nothing. Override as needed.
665 virtual void OnMouseEntered(const MouseEvent& event);
666
667 // This method is invoked when the mouse exits this control
668 // The provided event location is always (0, 0)
669 // Default implementation does nothing. Override as needed.
670 virtual void OnMouseExited(const MouseEvent& event);
671
672 // Set the MouseHandler for a drag session.
673 //
674 // A drag session is a stream of mouse events starting
675 // with a MousePressed event, followed by several MouseDragged
676 // events and finishing with a MouseReleased event.
677 //
678 // This method should be only invoked while processing a
679 // MouseDragged or MouseReleased event.
680 //
681 // All further mouse dragged and mouse up events will be sent
682 // the MouseHandler, even if it is reparented to another window.
683 //
684 // The MouseHandler is automatically cleared when the control
685 // comes back from processing the MouseReleased event.
686 //
687 // Note: if the mouse handler is no longer connected to a
688 // view hierarchy, events won't be sent.
689 //
690 virtual void SetMouseHandler(View* new_mouse_handler);
691
692 // Request the keyboard focus. The receiving view will become the
693 // focused view.
694 virtual void RequestFocus();
695
696 // Invoked when a view is about to gain focus
697 virtual void WillGainFocus();
698
699 // Invoked when a view just gained focus.
700 virtual void DidGainFocus();
701
702 // Invoked when a view is about lose focus
703 virtual void WillLoseFocus();
704
705 // Invoked when a view is about to be requested for focus due to the focus
706 // traversal. Reverse is this request was generated going backward
707 // (Shift-Tab).
708 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) { }
709
[email protected]ca13d804c2009-05-14 04:28:07710 // Invoked when a key is pressed before the key event is processed (and
711 // potentially eaten) by the focus manager for tab traversal, accelerators and
712 // other focus related actions.
713 // The default implementation returns false, ensuring that tab traversal and
714 // accelerators processing is performed.
715 // Subclasses should return true if they want to process the key event and not
716 // have it processed as an accelerator (if any) or as a tab traversal (if the
717 // key event is for the TAB key). In that case, OnKeyPressed will
718 // subsequently be invoked for that event.
719 virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& e) {
720 return false;
721 }
722
initial.commit09911bf2008-07-26 23:55:29723 // Invoked when a key is pressed or released.
724 // Subclasser should return true if the event has been processed and false
725 // otherwise. If the event has not been processed, the parent will be given a
726 // chance.
727 virtual bool OnKeyPressed(const KeyEvent& e);
728 virtual bool OnKeyReleased(const KeyEvent& e);
729
initial.commit09911bf2008-07-26 23:55:29730 // Invoked when the user uses the mousewheel. Implementors should return true
731 // if the event has been processed and false otherwise. This message is sent
732 // if the view is focused. If the event has not been processed, the parent
733 // will be given a chance.
734 virtual bool OnMouseWheel(const MouseWheelEvent& e);
735
736 // Drag and drop functions.
737
738 // Set/get the DragController. See description of DragController for more
739 // information.
740 void SetDragController(DragController* drag_controller);
741 DragController* GetDragController();
742
743 // During a drag and drop session when the mouse moves the view under the
[email protected]134c47b92009-08-19 03:33:44744 // mouse is queried for the drop types it supports by way of the
745 // GetDropFormats methods. If the view returns true and the drag site can
746 // provide data in one of the formats, the view is asked if the drop data
747 // is required before any other drop events are sent. Once the
748 // data is available the view is asked if it supports the drop (by way of
749 // the CanDrop method). If a view returns true from CanDrop,
initial.commit09911bf2008-07-26 23:55:29750 // OnDragEntered is sent to the view when the mouse first enters the view,
751 // as the mouse moves around within the view OnDragUpdated is invoked.
752 // If the user releases the mouse over the view and OnDragUpdated returns a
753 // valid drop, then OnPerformDrop is invoked. If the mouse moves outside the
754 // view or over another view that wants the drag, OnDragExited is invoked.
755 //
756 // Similar to mouse events, the deepest view under the mouse is first checked
757 // if it supports the drop (Drop). If the deepest view under
758 // the mouse does not support the drop, the ancestors are walked until one
759 // is found that supports the drop.
760
[email protected]134c47b92009-08-19 03:33:44761 // Override and return the set of formats that can be dropped on this view.
762 // |formats| is a bitmask of the formats defined bye OSExchangeData::Format.
763 // The default implementation returns false, which means the view doesn't
764 // support dropping.
765 virtual bool GetDropFormats(
766 int* formats,
767 std::set<OSExchangeData::CustomFormat>* custom_formats);
768
769 // Override and return true if the data must be available before any drop
770 // methods should be invoked. The default is false.
771 virtual bool AreDropTypesRequired();
772
initial.commit09911bf2008-07-26 23:55:29773 // A view that supports drag and drop must override this and return true if
774 // data contains a type that may be dropped on this view.
775 virtual bool CanDrop(const OSExchangeData& data);
776
777 // OnDragEntered is invoked when the mouse enters this view during a drag and
778 // drop session and CanDrop returns true. This is immediately
779 // followed by an invocation of OnDragUpdated, and eventually one of
780 // OnDragExited or OnPerformDrop.
781 virtual void OnDragEntered(const DropTargetEvent& event);
782
783 // Invoked during a drag and drop session while the mouse is over the view.
784 // This should return a bitmask of the DragDropTypes::DragOperation supported
785 // based on the location of the event. Return 0 to indicate the drop should
786 // not be accepted.
787 virtual int OnDragUpdated(const DropTargetEvent& event);
788
789 // Invoked during a drag and drop session when the mouse exits the views, or
790 // when the drag session was canceled and the mouse was over the view.
791 virtual void OnDragExited();
792
793 // Invoked during a drag and drop session when OnDragUpdated returns a valid
794 // operation and the user release the mouse.
795 virtual int OnPerformDrop(const DropTargetEvent& event);
796
797 // Returns true if the mouse was dragged enough to start a drag operation.
798 // delta_x and y are the distance the mouse was dragged.
799 static bool ExceededDragThreshold(int delta_x, int delta_y);
800
801 // This method is the main entry point to process paint for this
802 // view and its children. This method is called by the painting
803 // system. You should call this only if you want to draw a sub tree
804 // inside a custom graphics.
805 // To customize painting override either the Paint or PaintChildren method,
806 // not this one.
[email protected]82522512009-05-15 07:37:29807 virtual void ProcessPaint(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29808
809 // Paint the View's child Views, in reverse order.
[email protected]82522512009-05-15 07:37:29810 virtual void PaintChildren(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29811
812 // Sets the ContextMenuController. Setting this to non-null makes the View
813 // process mouse events.
814 void SetContextMenuController(ContextMenuController* menu_controller);
815 ContextMenuController* GetContextMenuController() {
816 return context_menu_controller_;
817 }
818
[email protected]042811c2008-10-31 21:31:34819 // Provides default implementation for context menu handling. The default
820 // implementation calls the ShowContextMenu of the current
821 // ContextMenuController (if it is not NULL). Overridden in subclassed views
822 // to provide right-click menu display triggerd by the keyboard (i.e. for the
823 // Chrome toolbar Back and Forward buttons). No source needs to be specified,
824 // as it is always equal to the current View.
825 virtual void ShowContextMenu(int x,
826 int y,
827 bool is_mouse_gesture);
828
[email protected]9a3f0ac22008-11-14 03:24:02829 // The background object is owned by this object and may be NULL.
830 void set_background(Background* b) { background_.reset(b); }
831 const Background* background() const { return background_.get(); }
initial.commit09911bf2008-07-26 23:55:29832
[email protected]9a3f0ac22008-11-14 03:24:02833 // The border object is owned by this object and may be NULL.
834 void set_border(Border* b) { border_.reset(b); }
835 const Border* border() const { return border_.get(); }
initial.commit09911bf2008-07-26 23:55:29836
837 // Returns the insets of the current border. If there is no border an empty
838 // insets is returned.
[email protected]a37bea82009-04-22 23:02:15839 virtual gfx::Insets GetInsets() const;
initial.commit09911bf2008-07-26 23:55:29840
841 // Return the cursor that should be used for this view or NULL if
842 // the default cursor should be used. The provided point is in the
[email protected]9abf8dd62009-06-04 06:40:42843 // receiver's coordinate system. The caller is responsible for managing the
844 // lifetime of the returned object, though that lifetime may vary from
845 // platform to platform. On Windows, the cursor is a shared resource but in
846 // Gtk, the framework destroys the returned cursor after setting it.
847 virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type,
848 int x,
849 int y);
initial.commit09911bf2008-07-26 23:55:29850
851 // Convenience to test whether a point is within this view's bounds
[email protected]613b8062008-10-14 23:45:09852 virtual bool HitTest(const gfx::Point& l) const;
initial.commit09911bf2008-07-26 23:55:29853
854 // Gets the tooltip for this View. If the View does not have a tooltip,
855 // return false. If the View does have a tooltip, copy the tooltip into
856 // the supplied string and return true.
857 // Any time the tooltip text that a View is displaying changes, it must
858 // invoke TooltipTextChanged.
859 // The x/y provide the coordinates of the mouse (relative to this view).
860 virtual bool GetTooltipText(int x, int y, std::wstring* tooltip);
861
862 // Returns the location (relative to this View) for the text on the tooltip
863 // to display. If false is returned (the default), the tooltip is placed at
864 // a default position.
[email protected]0a1d36b22008-10-17 19:33:09865 virtual bool GetTooltipTextOrigin(int x, int y, gfx::Point* loc);
initial.commit09911bf2008-07-26 23:55:29866
867 // Set whether this view is owned by its parent. A view that is owned by its
868 // parent is automatically deleted when the parent is deleted. The default is
869 // true. Set to false if the view is owned by another object and should not
870 // be deleted by its parent.
871 void SetParentOwned(bool f);
872
873 // Return whether a view is owned by its parent. See SetParentOwned()
874 bool IsParentOwned() const;
875
876 // Return the receiving view's class name. A view class is a string which
877 // uniquely identifies the view class. It is intended to be used as a way to
878 // find out during run time if a view can be safely casted to a specific view
879 // subclass. The default implementation returns kViewClassName.
880 virtual std::string GetClassName() const;
881
[email protected]5c2b98b2009-03-09 20:55:54882 // Returns the first ancestor, starting at this, whose class name is |name|.
883 // Returns null if no ancestor has the class name |name|.
884 View* GetAncestorWithClassName(const std::string& name);
885
initial.commit09911bf2008-07-26 23:55:29886 // Returns the visible bounds of the receiver in the receivers coordinate
887 // system.
888 //
889 // When traversing the View hierarchy in order to compute the bounds, the
890 // function takes into account the mirroring setting for each View and
891 // therefore it will return the mirrored version of the visible bounds if
892 // need be.
893 gfx::Rect GetVisibleBounds();
894
895 // Subclasses that contain traversable children that are not directly
896 // accessible through the children hierarchy should return the associated
897 // FocusTraversable for the focus traversal to work properly.
898 virtual FocusTraversable* GetFocusTraversable() { return NULL; }
899
900#ifndef NDEBUG
901 // Debug method that logs the view hierarchy to the output.
902 void PrintViewHierarchy();
903
904 // Debug method that logs the focus traversal hierarchy to the output.
905 void PrintFocusHierarchy();
906#endif
907
908 // The following methods are used by ScrollView to determine the amount
909 // to scroll relative to the visible bounds of the view. For example, a
910 // return value of 10 indicates the scrollview should scroll 10 pixels in
911 // the appropriate direction.
912 //
913 // Each method takes the following parameters:
914 //
915 // is_horizontal: if true, scrolling is along the horizontal axis, otherwise
916 // the vertical axis.
917 // is_positive: if true, scrolling is by a positive amount. Along the
918 // vertical axis scrolling by a positive amount equates to
919 // scrolling down.
920 //
921 // The return value should always be positive and gives the number of pixels
922 // to scroll. ScrollView interprets a return value of 0 (or negative)
923 // to scroll by a default amount.
924 //
925 // See VariableRowHeightScrollHelper and FixedRowHeightScrollHelper for
926 // implementations of common cases.
927 virtual int GetPageScrollIncrement(ScrollView* scroll_view,
928 bool is_horizontal, bool is_positive);
929 virtual int GetLineScrollIncrement(ScrollView* scroll_view,
930 bool is_horizontal, bool is_positive);
931
[email protected]4a190632009-05-09 01:07:42932 // Get the theme provider from the parent widget.
933 ThemeProvider* GetThemeProvider();
934
initial.commit09911bf2008-07-26 23:55:29935 protected:
initial.commit09911bf2008-07-26 23:55:29936 // The id of this View. Used to find this View.
937 int id_;
938
939 // The group of this view. Some view subclasses use this id to find other
940 // views of the same group. For example radio button uses this information
941 // to find other radio buttons.
942 int group_;
943
[email protected]32670b02009-03-03 00:28:00944 // Called when the UI theme has changed, overriding allows individual Views to
945 // do special cleanup and processing (such as dropping resource caches).
946 // Subclasses that override this method must call the base class
947 // implementation to ensure child views are processed.
948 // Can only be called by subclasses. To dispatch a theme changed notification,
949 // call this method on the RootView.
950 virtual void ThemeChanged();
951
initial.commit09911bf2008-07-26 23:55:29952#ifndef NDEBUG
953 // Returns true if the View is currently processing a paint.
954 virtual bool IsProcessingPaint() const;
955#endif
956
[email protected]f704ee72008-11-10 21:31:59957 // Returns the location, in screen coordinates, to show the context menu at
958 // when the context menu is shown from the keyboard. This implementation
959 // returns the middle of the visible region of this view.
960 //
961 // This method is invoked when the context menu is shown by way of the
962 // keyboard.
963 virtual gfx::Point GetKeyboardContextMenuLocation();
964
[email protected]82739cf2008-09-16 00:37:56965 // Called by HitTest to see if this View has a custom hit test mask. If the
966 // return value is true, GetHitTestMask will be called to obtain the mask.
967 // Default value is false, in which case the View will hit-test against its
968 // bounds.
969 virtual bool HasHitTestMask() const;
970
971 // Called by HitTest to retrieve a mask for hit-testing against. Subclasses
972 // override to provide custom shaped hit test regions.
973 virtual void GetHitTestMask(gfx::Path* mask) const;
974
initial.commit09911bf2008-07-26 23:55:29975 // This method is invoked when the tree changes.
976 //
977 // When a view is removed, it is invoked for all children and grand
978 // children. For each of these views, a notification is sent to the
979 // view and all parents.
980 //
981 // When a view is added, a notification is sent to the view, all its
982 // parents, and all its children (and grand children)
983 //
984 // Default implementation does nothing. Override to perform operations
985 // required when a view is added or removed from a view hierarchy
986 //
987 // parent is the new or old parent. Child is the view being added or
988 // removed.
989 //
990 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
991
992 // When SetVisible() changes the visibility of a view, this method is
993 // invoked for that view as well as all the children recursively.
994 virtual void VisibilityChanged(View* starting_from, bool is_visible);
995
[email protected]7ccc52b72009-05-08 21:09:11996 // Called when the preferred size of a child view changed. This gives the
997 // parent an opportunity to do a fresh layout if that makes sense.
998 virtual void ChildPreferredSizeChanged(View* child) {}
999
1000 // Simply calls ChildPreferredSizeChanged on the parent if there is one.
1001 virtual void PreferredSizeChanged();
1002
initial.commit09911bf2008-07-26 23:55:291003 // Views must invoke this when the tooltip text they are to display changes.
1004 void TooltipTextChanged();
1005
initial.commit09911bf2008-07-26 23:55:291006 // Sets whether this view wants notification when its visible bounds relative
1007 // to the root view changes. If true, this view is notified any time the
1008 // origin of one its ancestors changes, or the portion of the bounds not
1009 // obscured by ancestors changes. The default is false.
1010 void SetNotifyWhenVisibleBoundsInRootChanges(bool value);
1011 bool GetNotifyWhenVisibleBoundsInRootChanges();
1012
1013 // Notification that this views visible bounds, relative to the RootView
1014 // has changed. The visible bounds corresponds to the region of the
1015 // view not obscured by other ancestors.
1016 virtual void VisibleBoundsInRootChanged() {}
1017
1018 // Sets the keyboard focus to this View. The correct way to set the focus is
1019 // to call RequestFocus() on the view. This method is called when the focus is
1020 // set and gives an opportunity to subclasses to perform any extra focus steps
1021 // (for example native component set the native focus on their native
1022 // component). The default behavior is to set the native focus on the root
[email protected]a0dde122008-11-21 20:51:201023 // Widget, which is what is appropriate for views that have no native window
1024 // associated with them (so the root view gets the keyboard messages).
initial.commit09911bf2008-07-26 23:55:291025 virtual void Focus();
1026
initial.commit09911bf2008-07-26 23:55:291027 // These are cover methods that invoke the method of the same name on
1028 // the DragController. Subclasses may wish to override rather than install
1029 // a DragController.
1030 // See DragController for a description of these methods.
1031 virtual int GetDragOperations(int press_x, int press_y);
1032 virtual void WriteDragData(int press_x, int press_y, OSExchangeData* data);
1033
1034 // Invoked from DoDrag after the drag completes. This implementation does
1035 // nothing, and is intended for subclasses to do cleanup.
1036 virtual void OnDragDone();
1037
1038 // Returns whether we're in the middle of a drag session that was initiated
1039 // by us.
1040 bool InDrag();
1041
[email protected]253a39a2009-05-29 20:45:131042 // Returns how much the mouse needs to move in one direction to start a
1043 // drag. These methods cache in a platform-appropriate way. These values are
1044 // used by the public static method ExceededDragThreshold().
1045 static int GetHorizontalDragThreshold();
1046 static int GetVerticalDragThreshold();
1047
initial.commit09911bf2008-07-26 23:55:291048 // Whether this view is enabled.
1049 bool enabled_;
1050
1051 // Whether the view can be focused.
1052 bool focusable_;
1053
1054 private:
1055 friend class RootView;
1056 friend class FocusManager;
1057 friend class ViewStorage;
1058
1059 // Used to track a drag. RootView passes this into
1060 // ProcessMousePressed/Dragged.
1061 struct DragInfo {
1062 // Sets possible_drag to false and start_x/y to 0. This is invoked by
1063 // RootView prior to invoke ProcessMousePressed.
1064 void Reset();
1065
1066 // Sets possible_drag to true and start_x/y to the specified coordinates.
1067 // This is invoked by the target view if it detects the press may generate
1068 // a drag.
1069 void PossibleDrag(int x, int y);
1070
1071 // Whether the press may generate a drag.
1072 bool possible_drag;
1073
1074 // Coordinates of the mouse press.
1075 int start_x;
1076 int start_y;
1077 };
1078
1079 // RootView invokes these. These in turn invoke the appropriate OnMouseXXX
1080 // method. If a drag is detected, DoDrag is invoked.
1081 bool ProcessMousePressed(const MouseEvent& e, DragInfo* drop_info);
1082 bool ProcessMouseDragged(const MouseEvent& e, DragInfo* drop_info);
1083 void ProcessMouseReleased(const MouseEvent& e, bool canceled);
1084
1085 // Starts a drag and drop operation originating from this view. This invokes
1086 // WriteDragData to write the data and GetDragOperations to determine the
1087 // supported drag operations. When done, OnDragDone is invoked.
[email protected]c2dacc92008-10-16 23:51:381088 void DoDrag(const MouseEvent& e, int press_x, int press_y);
initial.commit09911bf2008-07-26 23:55:291089
initial.commit09911bf2008-07-26 23:55:291090 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true,
1091 // the next and previous focusable views of views pointing to this view are
1092 // updated. If |update_tool_tip| is true, the tooltip is updated. If
1093 // |delete_removed_view| is true, the view is also deleted (if it is parent
1094 // owned).
1095 void DoRemoveChildView(View* view,
1096 bool update_focus_cycle,
1097 bool update_tool_tip,
1098 bool delete_removed_view);
1099
1100 // Sets the parent View. This is called automatically by AddChild and is
1101 // thus private.
1102 void SetParent(View *parent);
1103
1104 // Call ViewHierarchyChanged for all child views on all parents
1105 void PropagateRemoveNotifications(View* parent);
1106
1107 // Call ViewHierarchyChanged for all children
1108 void PropagateAddNotifications(View* parent, View* child);
1109
1110 // Call VisibilityChanged() recursively for all children.
1111 void PropagateVisibilityNotifications(View* from, bool is_visible);
1112
1113 // Takes care of registering/unregistering accelerators if
1114 // |register_accelerators| true and calls ViewHierarchyChanged().
1115 void ViewHierarchyChangedImpl(bool register_accelerators,
[email protected]bb515ed2009-01-15 00:53:431116 bool is_add,
1117 View* parent,
1118 View* child);
initial.commit09911bf2008-07-26 23:55:291119
1120 // This is the actual implementation for ConvertPointToView()
1121 // Attempts a parent -> child conversion and then a
1122 // child -> parent conversion if try_other_direction is true
[email protected]bb515ed2009-01-15 00:53:431123 static void ConvertPointToView(const View* src,
1124 const View* dst,
initial.commit09911bf2008-07-26 23:55:291125 gfx::Point* point,
1126 bool try_other_direction);
1127
[email protected]a0dde122008-11-21 20:51:201128 // Propagates UpdateTooltip() to the TooltipManager for the Widget.
initial.commit09911bf2008-07-26 23:55:291129 // This must be invoked any time the View hierarchy changes in such a way
1130 // the view under the mouse differs. For example, if the bounds of a View is
1131 // changed, this is invoked. Similarly, as Views are added/removed, this
1132 // is invoked.
1133 void UpdateTooltip();
1134
1135 // Recursively descends through all descendant views,
1136 // registering/unregistering all views that want visible bounds in root
1137 // view notification.
1138 static void RegisterChildrenForVisibleBoundsNotification(RootView* root,
1139 View* view);
1140 static void UnregisterChildrenForVisibleBoundsNotification(RootView* root,
1141 View* view);
1142
1143 // Adds/removes view to the list of descendants that are notified any time
1144 // this views location and possibly size are changed.
1145 void AddDescendantToNotify(View* view);
1146 void RemoveDescendantToNotify(View* view);
1147
1148 // Initialize the previous/next focusable views of the specified view relative
1149 // to the view at the specified index.
1150 void InitFocusSiblings(View* view, int index);
1151
1152 // Actual implementation of PrintFocusHierarchy.
1153 void PrintViewHierarchyImp(int indent);
1154 void PrintFocusHierarchyImp(int indent);
1155
[email protected]71421c3f2009-06-06 00:41:441156 // Registers this view's keyboard accelerators that are not registered to
1157 // FocusManager yet, if possible.
1158 void RegisterPendingAccelerators();
1159
1160 // Unregisters all the keyboard accelerators associated with this view.
initial.commit09911bf2008-07-26 23:55:291161 void UnregisterAccelerators();
1162
[email protected]80f8b9f2008-10-16 18:17:471163 // This View's bounds in the parent coordinate system.
1164 gfx::Rect bounds_;
1165
initial.commit09911bf2008-07-26 23:55:291166 // This view's parent
1167 View *parent_;
1168
1169 // This view's children.
1170 typedef std::vector<View*> ViewList;
1171 ViewList child_views_;
1172
initial.commit09911bf2008-07-26 23:55:291173 // The View's LayoutManager defines the sizing heuristics applied to child
1174 // Views. The default is absolute positioning according to bounds_.
1175 scoped_ptr<LayoutManager> layout_manager_;
1176
1177 // Visible state
1178 bool is_visible_;
1179
1180 // Background
[email protected]9a3f0ac22008-11-14 03:24:021181 scoped_ptr<Background> background_;
initial.commit09911bf2008-07-26 23:55:291182
1183 // Border.
[email protected]9a3f0ac22008-11-14 03:24:021184 scoped_ptr<Border> border_;
initial.commit09911bf2008-07-26 23:55:291185
1186 // Whether this view is owned by its parent.
1187 bool is_parent_owned_;
1188
1189 // See SetNotifyWhenVisibleBoundsInRootChanges.
1190 bool notify_when_visible_bounds_in_root_changes_;
1191
1192 // Whether or not RegisterViewForVisibleBoundsNotification on the RootView
1193 // has been invoked.
1194 bool registered_for_visible_bounds_notification_;
1195
1196 // List of descendants wanting notification when their visible bounds change.
1197 scoped_ptr<ViewList> descendants_to_notify_;
1198
1199 // Next view to be focused when the Tab key is pressed.
1200 View* next_focusable_view_;
1201
1202 // Next view to be focused when the Shift-Tab key combination is pressed.
1203 View* previous_focusable_view_;
1204
[email protected]71421c3f2009-06-06 00:41:441205 // The list of accelerators. List elements in the range
1206 // [0, registered_accelerator_count_) are already registered to FocusManager,
1207 // and the rest are not yet.
[email protected]1eb89e82008-08-15 12:27:031208 scoped_ptr<std::vector<Accelerator> > accelerators_;
[email protected]4bd23f32009-06-08 20:59:191209 size_t registered_accelerator_count_;
initial.commit09911bf2008-07-26 23:55:291210
initial.commit09911bf2008-07-26 23:55:291211 // The menu controller.
1212 ContextMenuController* context_menu_controller_;
1213
[email protected]6ff244f2009-01-20 20:38:081214#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291215 // The accessibility implementation for this View.
[email protected]fef10642009-03-17 21:17:041216 scoped_ptr<ViewAccessibilityWrapper> accessibility_;
[email protected]6ff244f2009-01-20 20:38:081217#endif
initial.commit09911bf2008-07-26 23:55:291218
1219 DragController* drag_controller_;
1220
1221 // Indicates whether or not the view is going to be mirrored (that is, use a
1222 // right-to-left UI layout) if the locale's language is a right-to-left
1223 // language like Arabic or Hebrew.
1224 bool ui_mirroring_is_enabled_for_rtl_languages_;
1225
[email protected]82522512009-05-15 07:37:291226 // Indicates whether or not the gfx::Canvas object passed to View::Paint()
initial.commit09911bf2008-07-26 23:55:291227 // is going to be flipped horizontally (using the appropriate transform) on
1228 // right-to-left locales for this View.
1229 bool flip_canvas_on_paint_for_rtl_ui_;
1230
[email protected]1eb89e82008-08-15 12:27:031231 DISALLOW_COPY_AND_ASSIGN(View);
initial.commit09911bf2008-07-26 23:55:291232};
1233
[email protected]c2dacc92008-10-16 23:51:381234} // namespace views
initial.commit09911bf2008-07-26 23:55:291235
[email protected]2362e4f2009-05-08 00:34:051236#endif // VIEWS_VIEW_H_