blob: 13a85eed86fd2c40fa5f2d4a9d65625ce1f4ebb9 [file] [log] [blame]
[email protected]20cb5f482009-12-16 01:01:251// Copyright (c) 2009 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]010ea08a2009-10-11 20:21:3216#include "app/gfx/native_widget_types.h"
[email protected]134c47b92009-08-19 03:33:4417#include "app/os_exchange_data.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;
[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,
84 int press_x,
85 int press_y,
86 OSExchangeData* data) = 0;
87
88 // Returns the supported drag operations (see DragDropTypes for possible
89 // values). A drag is only started if this returns a non-zero value.
90 virtual int GetDragOperations(View* sender, int x, int y) = 0;
initial.commit09911bf2008-07-26 23:55:2991
[email protected]b5f94de2009-12-04 07:59:0092 // Returns true if a drag operation can be started.
93 // |press_x| and |press_y| represent coordinates where mouse was initially
94 // pressed down. |x| and |y| are the current mouse coordinates.
95 virtual bool CanStartDrag(View* sender,
96 int press_x,
97 int press_y,
98 int x,
99 int y) = 0;
[email protected]20cb5f482009-12-16 01:01:25100
101 protected:
102 virtual ~DragController() {}
[email protected]b5f94de2009-12-04 07:59:00103};
initial.commit09911bf2008-07-26 23:55:29104
105/////////////////////////////////////////////////////////////////////////////
106//
107// View class
108//
[email protected]c2dacc92008-10-16 23:51:38109// A View is a rectangle within the views View hierarchy. It is the base
[email protected]1bc83062009-02-06 00:16:37110// class for all Views.
initial.commit09911bf2008-07-26 23:55:29111//
112// A View is a container of other Views (there is no such thing as a Leaf
113// View - makes code simpler, reduces type conversion headaches, design
114// mistakes etc)
115//
116// The View contains basic properties for sizing (bounds), layout (flex,
117// orientation, etc), painting of children and event dispatch.
118//
119// The View also uses a simple Box Layout Manager similar to XUL's
120// SprocketLayout system. Alternative Layout Managers implementing the
121// LayoutManager interface can be used to lay out children if required.
122//
123// It is up to the subclass to implement Painting and storage of subclass -
124// specific properties and functionality.
125//
126/////////////////////////////////////////////////////////////////////////////
127class View : public AcceleratorTarget {
128 public:
[email protected]6f3bb6c2008-09-17 22:25:33129 // Used in the versions of GetBounds() and x() that take a transformation
initial.commit09911bf2008-07-26 23:55:29130 // parameter in order to determine whether or not to take into account the
131 // mirroring setting of the View when returning bounds positions.
132 enum PositionMirroringSettings {
133 IGNORE_MIRRORING_TRANSFORMATION = 0,
134 APPLY_MIRRORING_TRANSFORMATION
135 };
136
137 // The view class name.
138 static char kViewClassName[];
139
140 View();
141 virtual ~View();
142
[email protected]aadcd1d92009-09-22 18:11:31143 // Returns the amount of time between double clicks, in milliseconds.
144 static int GetDoubleClickTimeMS();
145
initial.commit09911bf2008-07-26 23:55:29146 // Sizing functions
147
148 // Get the bounds of the View, relative to the parent. Essentially, this
149 // function returns the bounds_ rectangle.
150 //
151 // This is the function subclasses should use whenever they need to obtain
152 // the bounds of one of their child views (for example, when implementing
153 // View::Layout()).
[email protected]24db2eb2009-07-17 17:54:16154 const gfx::Rect& bounds() const { return bounds_; }
[email protected]80f8b9f2008-10-16 18:17:47155
156 // Get the size of the View.
[email protected]24db2eb2009-07-17 17:54:16157 const gfx::Size& size() const { return bounds_.size(); }
initial.commit09911bf2008-07-26 23:55:29158
159 // Return the bounds of the View, relative to the parent. If
160 // |settings| is IGNORE_MIRRORING_TRANSFORMATION, the function returns the
[email protected]8f763a302009-11-11 00:47:32161 // bounds_ rectangle. If |settings| is APPLY_MIRRORING_TRANSFORMATION AND the
initial.commit09911bf2008-07-26 23:55:29162 // parent View is using a right-to-left UI layout, then the function returns
163 // a shifted version of the bounds_ rectangle that represents the mirrored
164 // View bounds.
165 //
166 // NOTE: in the vast majority of the cases, the mirroring implementation is
167 // transparent to the View subclasses and therefore you should use the
168 // version of GetBounds() which does not take a transformation settings
169 // parameter.
[email protected]0d8ea702008-10-14 17:03:07170 gfx::Rect GetBounds(PositionMirroringSettings settings) const;
initial.commit09911bf2008-07-26 23:55:29171
172 // Set the bounds in the parent's coordinate system.
[email protected]80f8b9f2008-10-16 18:17:47173 void SetBounds(const gfx::Rect& bounds);
174 void SetBounds(int x, int y, int width, int height) {
175 SetBounds(gfx::Rect(x, y, std::max(0, width), std::max(0, height)));
176 }
[email protected]6f3bb6c2008-09-17 22:25:33177 void SetX(int x) { SetBounds(x, y(), width(), height()); }
178 void SetY(int y) { SetBounds(x(), y, width(), height()); }
initial.commit09911bf2008-07-26 23:55:29179
180 // Returns the left coordinate of the View, relative to the parent View,
[email protected]80f8b9f2008-10-16 18:17:47181 // which is the value of bounds_.x().
initial.commit09911bf2008-07-26 23:55:29182 //
183 // This is the function subclasses should use whenever they need to obtain
184 // the left position of one of their child views (for example, when
185 // implementing View::Layout()).
[email protected]0a1d36b22008-10-17 19:33:09186 // This is equivalent to GetX(IGNORE_MIRRORING_TRANSFORMATION), but
187 // inlinable.
188 int x() const { return bounds_.x(); }
189 int y() const { return bounds_.y(); }
190 int width() const { return bounds_.width(); }
191 int height() const { return bounds_.height(); }
initial.commit09911bf2008-07-26 23:55:29192
193 // Return the left coordinate of the View, relative to the parent. If
194 // |settings| is IGNORE_MIRRORING_SETTINGS, the function returns the value of
[email protected]80f8b9f2008-10-16 18:17:47195 // bounds_.x(). If |settings| is APPLY_MIRRORING_SETTINGS AND the parent
initial.commit09911bf2008-07-26 23:55:29196 // View is using a right-to-left UI layout, then the function returns the
[email protected]80f8b9f2008-10-16 18:17:47197 // mirrored value of bounds_.x().
initial.commit09911bf2008-07-26 23:55:29198 //
199 // NOTE: in the vast majority of the cases, the mirroring implementation is
200 // transparent to the View subclasses and therefore you should use the
[email protected]6f3bb6c2008-09-17 22:25:33201 // paremeterless version of x() when you need to get the X
initial.commit09911bf2008-07-26 23:55:29202 // coordinate of a child View.
203 int GetX(PositionMirroringSettings settings) const;
204
initial.commit09911bf2008-07-26 23:55:29205 // Return this control local bounds. If include_border is true, local bounds
[email protected]6f3bb6c2008-09-17 22:25:33206 // is the rectangle {0, 0, width(), height()}, otherwise, it does not
initial.commit09911bf2008-07-26 23:55:29207 // include the area where the border (if any) is painted.
[email protected]80f8b9f2008-10-16 18:17:47208 gfx::Rect GetLocalBounds(bool include_border) const;
initial.commit09911bf2008-07-26 23:55:29209
210 // Get the position of the View, relative to the parent.
211 //
212 // Note that if the parent uses right-to-left UI layout, then the mirrored
[email protected]6f3bb6c2008-09-17 22:25:33213 // position of this View is returned. Use x()/y() if you want to ignore
initial.commit09911bf2008-07-26 23:55:29214 // mirroring.
[email protected]0a1d36b22008-10-17 19:33:09215 gfx::Point GetPosition() const;
initial.commit09911bf2008-07-26 23:55:29216
217 // Get the size the View would like to be, if enough space were available.
[email protected]154f8bc2008-10-15 18:02:30218 virtual gfx::Size GetPreferredSize();
initial.commit09911bf2008-07-26 23:55:29219
[email protected]a1360162009-11-30 21:19:07220 // Returns the baseline of this view, or -1 if this view has no baseline. The
221 // return value is relative to the preferred height.
222 virtual int GetBaseline();
223
initial.commit09911bf2008-07-26 23:55:29224 // Convenience method that sizes this view to its preferred size.
225 void SizeToPreferredSize();
226
227 // Gets the minimum size of the view. View's implementation invokes
228 // GetPreferredSize.
[email protected]154f8bc2008-10-15 18:02:30229 virtual gfx::Size GetMinimumSize();
initial.commit09911bf2008-07-26 23:55:29230
231 // Return the height necessary to display this view with the provided width.
232 // View's implementation returns the value from getPreferredSize.cy.
233 // Override if your View's preferred height depends upon the width (such
234 // as with Labels).
235 virtual int GetHeightForWidth(int w);
236
237 // This method is invoked when this object size or position changes.
238 // The default implementation does nothing.
[email protected]80f8b9f2008-10-16 18:17:47239 virtual void DidChangeBounds(const gfx::Rect& previous,
240 const gfx::Rect& current);
initial.commit09911bf2008-07-26 23:55:29241
242 // Set whether the receiving view is visible. Painting is scheduled as needed
243 virtual void SetVisible(bool flag);
244
245 // Return whether a view is visible
246 virtual bool IsVisible() const { return is_visible_; }
247
248 // Return whether a view and its ancestors are visible. Returns true if the
249 // path from this view to the root view is visible.
250 virtual bool IsVisibleInRootView() const;
251
252 // Set whether this view is enabled. A disabled view does not receive keyboard
253 // or mouse inputs. If flag differs from the current value, SchedulePaint is
254 // invoked.
255 virtual void SetEnabled(bool flag);
256
257 // Returns whether the view is enabled.
258 virtual bool IsEnabled() const;
259
260 // Set whether this view is hottracked. A disabled view cannot be hottracked.
261 // If flag differs from the current value, SchedulePaint is invoked.
262 virtual void SetHotTracked(bool flag);
263
264 // Returns whether the view is hot-tracked.
265 virtual bool IsHotTracked() const { return false; }
266
267 // Returns whether the view is pushed.
268 virtual bool IsPushed() const { return false; }
269
270 // Scrolls the specified region, in this View's coordinate system, to be
271 // visible. View's implementation passes the call onto the parent View (after
272 // adjusting the coordinates). It is up to views that only show a portion of
273 // the child view, such as Viewport, to override appropriately.
274 virtual void ScrollRectToVisible(int x, int y, int width, int height);
275
276 // Layout functions
277
278 // Lay out the child Views (set their bounds based on sizing heuristics
279 // specific to the current Layout Manager)
280 virtual void Layout();
281
282 // Gets/Sets the Layout Manager used by this view to size and place its
283 // children.
284 // The LayoutManager is owned by the View and is deleted when the view is
285 // deleted, or when a new LayoutManager is installed.
286 LayoutManager* GetLayoutManager() const;
287 void SetLayoutManager(LayoutManager* layout);
288
289 // Right-to-left UI layout functions
290
291 // Indicates whether the UI layout for this view is right-to-left. The view
292 // has an RTL UI layout if RTL hasn't been disabled for the view and if the
293 // locale's language is an RTL language.
[email protected]1eb89e82008-08-15 12:27:03294 bool UILayoutIsRightToLeft() const;
initial.commit09911bf2008-07-26 23:55:29295
296 // Enables or disables the right-to-left layout for the view. If |enable| is
297 // true, the layout will become right-to-left only if the locale's language
298 // is right-to-left.
299 //
300 // By default, right-to-left UI layout is enabled for the view and therefore
301 // this function must be called (with false as the |enable| parameter) in
302 // order to disable the right-to-left layout property for a specific instance
303 // of the view. Disabling the right-to-left UI layout is necessary in case a
304 // UI element will not appear correctly when mirrored.
305 void EnableUIMirroringForRTLLanguages(bool enable) {
306 ui_mirroring_is_enabled_for_rtl_languages_ = enable;
307 }
308
[email protected]82522512009-05-15 07:37:29309 // This method determines whether the gfx::Canvas object passed to
initial.commit09911bf2008-07-26 23:55:29310 // View::Paint() needs to be transformed such that anything drawn on the
311 // canvas object during View::Paint() is flipped horizontally.
312 //
313 // By default, this function returns false (which is the initial value of
314 // |flip_canvas_on_paint_for_rtl_ui_|). View subclasses that need to paint on
[email protected]82522512009-05-15 07:37:29315 // a flipped gfx::Canvas when the UI layout is right-to-left need to call
initial.commit09911bf2008-07-26 23:55:29316 // EnableCanvasFlippingForRTLUI().
317 bool FlipCanvasOnPaintForRTLUI() const {
318 return flip_canvas_on_paint_for_rtl_ui_ ? UILayoutIsRightToLeft() : false;
319 }
320
[email protected]82522512009-05-15 07:37:29321 // Enables or disables flipping of the gfx::Canvas during View::Paint().
initial.commit09911bf2008-07-26 23:55:29322 // Note that if canvas flipping is enabled, the canvas will be flipped only
323 // if the UI layout is right-to-left; that is, the canvas will be flipped
324 // only if UILayoutIsRightToLeft() returns true.
325 //
326 // Enabling canvas flipping is useful for leaf views that draw a bitmap that
327 // needs to be flipped horizontally when the UI layout is right-to-left
[email protected]c2dacc92008-10-16 23:51:38328 // (views::Button, for example). This method is helpful for such classes
329 // because their drawing logic stays the same and they can become agnostic to
330 // the UI directionality.
initial.commit09911bf2008-07-26 23:55:29331 void EnableCanvasFlippingForRTLUI(bool enable) {
332 flip_canvas_on_paint_for_rtl_ui_ = enable;
333 }
334
335 // Returns the mirrored X position for the view, relative to the parent. If
336 // the parent view is not mirrored, this function returns bound_.left.
337 //
338 // UI mirroring is transparent to most View subclasses and therefore there is
339 // no need to call this routine from anywhere within your subclass
340 // implementation.
[email protected]63329982008-10-10 21:56:57341 int MirroredX() const;
initial.commit09911bf2008-07-26 23:55:29342
343 // Given a rectangle specified in this View's coordinate system, the function
344 // computes the 'left' value for the mirrored rectangle within this View. If
345 // the View's UI layout is not right-to-left, then bounds.x() is returned.
346 //
347 // UI mirroring is transparent to most View subclasses and therefore there is
348 // no need to call this routine from anywhere within your subclass
349 // implementation.
350 int MirroredLeftPointForRect(const gfx::Rect& rect) const;
351
352 // Given the X coordinate of a point inside the View, this function returns
353 // the mirrored X coordinate of the point if the View's UI layout is
354 // right-to-left. If the layout is left-to-right, the same X coordinate is
355 // returned.
356 //
357 // Following are a few examples of the values returned by this function for
358 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout:
359 //
360 // MirroredXCoordinateInsideView(0) -> 100
361 // MirroredXCoordinateInsideView(20) -> 80
362 // MirroredXCoordinateInsideView(99) -> 1
363 int MirroredXCoordinateInsideView(int x) const {
[email protected]6f3bb6c2008-09-17 22:25:33364 return UILayoutIsRightToLeft() ? width() - x : x;
initial.commit09911bf2008-07-26 23:55:29365 }
366
[email protected]14da3dff2009-06-12 18:01:47367 // Given a X coordinate and a width inside the View, this function returns
368 // the mirrored X coordinate if the View's UI layout is right-to-left. If the
369 // layout is left-to-right, the same X coordinate is returned.
370 //
371 // Following are a few examples of the values returned by this function for
372 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout:
373 //
374 // MirroredXCoordinateInsideView(0, 10) -> 90
375 // MirroredXCoordinateInsideView(20, 20) -> 60
376 int MirroredXWithWidthInsideView(int x, int w) const {
377 return UILayoutIsRightToLeft() ? width() - x - w : x;
378 }
379
initial.commit09911bf2008-07-26 23:55:29380 // Painting functions
381
382 // Mark the specified rectangle as dirty (needing repaint). If |urgent| is
383 // true, the view will be repainted when the current event processing is
384 // done. Otherwise, painting will take place as soon as possible.
[email protected]0a1d36b22008-10-17 19:33:09385 virtual void SchedulePaint(const gfx::Rect& r, bool urgent);
initial.commit09911bf2008-07-26 23:55:29386
387 // Mark the entire View's bounds as dirty. Painting will occur as soon as
388 // possible.
389 virtual void SchedulePaint();
390
391 // Convenience to schedule a paint given some ints. Painting will occur as
392 // soon as possible.
393 virtual void SchedulePaint(int x, int y, int w, int h);
394
395 // Paint the receiving view. g is prepared such as it is in
396 // receiver's coordinate system. g's state is restored after this
397 // call so your implementation can change the graphics configuration
398 //
399 // Default implementation paints the background if it is defined
400 //
401 // Override this method when implementing a new control.
[email protected]82522512009-05-15 07:37:29402 virtual void Paint(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29403
404 // Paint the background if any. This method is called by Paint() and
405 // should rarely be invoked directly.
[email protected]82522512009-05-15 07:37:29406 virtual void PaintBackground(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29407
408 // Paint the border if any. This method is called by Paint() and
409 // should rarely be invoked directly.
[email protected]82522512009-05-15 07:37:29410 virtual void PaintBorder(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29411
412 // Paints the focus border (only if the view has the focus).
413 // This method is called by Paint() and should rarely be invoked directly.
414 // The default implementation paints a gray border around the view. Override
415 // it for custom focus effects.
[email protected]82522512009-05-15 07:37:29416 virtual void PaintFocusBorder(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29417
418 // Paint this View immediately.
419 virtual void PaintNow();
420
initial.commit09911bf2008-07-26 23:55:29421 // Tree functions
422
423 // Add a child View.
424 void AddChildView(View* v);
425
426 // Adds a child View at the specified position.
427 void AddChildView(int index, View* v);
428
429 // Get the child View at the specified index.
430 View* GetChildViewAt(int index) const;
431
432 // Remove a child view from this view. v's parent will change to NULL
433 void RemoveChildView(View *v);
434
435 // Remove all child view from this view. If |delete_views| is true, the views
436 // are deleted, unless marked as not parent owned.
437 void RemoveAllChildViews(bool delete_views);
438
439 // Get the number of child Views.
440 int GetChildViewCount() const;
441
[email protected]24db2eb2009-07-17 17:54:16442 // Returns the deepest descendant that contains the specified point.
[email protected]613b8062008-10-14 23:45:09443 virtual View* GetViewForPoint(const gfx::Point& point);
initial.commit09911bf2008-07-26 23:55:29444
[email protected]a0dde122008-11-21 20:51:20445 // Get the Widget that hosts this View, if any.
446 virtual Widget* GetWidget() const;
initial.commit09911bf2008-07-26 23:55:29447
[email protected]cd8c47902009-04-30 20:55:35448 // Gets the Widget that most closely contains this View, if any.
[email protected]08a3b712009-10-14 18:03:47449 // NOTE: almost all views displayed on screen have a Widget, but not
450 // necessarily a Window. This is due to widgets being able to create top
451 // level windows (as is done for popups, bubbles and menus).
[email protected]cd8c47902009-04-30 20:55:35452 virtual Window* GetWindow() const;
453
initial.commit09911bf2008-07-26 23:55:29454 // Get the containing RootView
455 virtual RootView* GetRootView();
456
457 // Get the parent View
458 View* GetParent() const { return parent_; }
459
460 // Returns the index of the specified |view| in this view's children, or -1
461 // if the specified view is not a child of this view.
462 int GetChildIndex(View* v) const;
463
464 // Returns true if the specified view is a direct or indirect child of this
465 // view.
466 bool IsParentOf(View* v) const;
467
468 // Recursively descends the view tree starting at this view, and returns
469 // the first child that it encounters that has the given ID.
470 // Returns NULL if no matching child view is found.
471 virtual View* GetViewByID(int id) const;
472
473 // Sets and gets the ID for this view. ID should be unique within the subtree
474 // that you intend to search for it. 0 is the default ID for views.
475 void SetID(int id);
476 int GetID() const;
477
478 // A group id is used to tag views which are part of the same logical group.
479 // Focus can be moved between views with the same group using the arrow keys.
480 // Groups are currently used to implement radio button mutual exclusion.
[email protected]96f960d2009-09-14 18:45:30481 // The group id is immutable once it's set.
initial.commit09911bf2008-07-26 23:55:29482 void SetGroup(int gid);
[email protected]96f960d2009-09-14 18:45:30483 // Returns the group id of the view, or -1 if the id is not set yet.
initial.commit09911bf2008-07-26 23:55:29484 int GetGroup() const;
485
486 // If this returns true, the views from the same group can each be focused
487 // when moving focus with the Tab/Shift-Tab key. If this returns false,
488 // only the selected view from the group (obtained with
489 // GetSelectedViewForGroup()) is focused.
490 virtual bool IsGroupFocusTraversable() const { return true; }
491
492 // Fills the provided vector with all the available views which belong to the
493 // provided group.
494 void GetViewsWithGroup(int group_id, std::vector<View*>* out);
495
496 // Return the View that is currently selected in the specified group.
497 // The default implementation simply returns the first View found for that
498 // group.
499 virtual View* GetSelectedViewForGroup(int group_id);
500
501 // Focus support
502 //
503 // Returns the view that should be selected next when pressing Tab.
504 View* GetNextFocusableView();
505
506 // Returns the view that should be selected next when pressing Shift-Tab.
507 View* GetPreviousFocusableView();
508
509 // Sets the component that should be selected next when pressing Tab, and
510 // makes the current view the precedent view of the specified one.
511 // Note that by default views are linked in the order they have been added to
512 // their container. Use this method if you want to modify the order.
513 // IMPORTANT NOTE: loops in the focus hierarchy are not supported.
514 void SetNextFocusableView(View* view);
515
516 // Return whether this view can accept the focus.
517 virtual bool IsFocusable() const;
518
519 // Sets whether this view can accept the focus.
520 // Note that this is false by default so that a view used as a container does
521 // not get the focus.
522 virtual void SetFocusable(bool focusable);
523
524 // Convenience method to retrieve the FocusManager associated with the
[email protected]a0dde122008-11-21 20:51:20525 // Widget that contains this view. This can return NULL if this view is not
526 // part of a view hierarchy with a Widget.
initial.commit09911bf2008-07-26 23:55:29527 virtual FocusManager* GetFocusManager();
528
529 // Sets a keyboard accelerator for that view. When the user presses the
530 // accelerator key combination, the AcceleratorPressed method is invoked.
531 // Note that you can set multiple accelerators for a view by invoking this
532 // method several times.
533 virtual void AddAccelerator(const Accelerator& accelerator);
534
[email protected]e8e0f362008-11-08 01:13:25535 // Removes the specified accelerator for this view.
536 virtual void RemoveAccelerator(const Accelerator& accelerator);
537
initial.commit09911bf2008-07-26 23:55:29538 // Removes all the keyboard accelerators for this view.
539 virtual void ResetAccelerators();
540
541 // Called when a keyboard accelerator is pressed.
542 // Derived classes should implement desired behavior and return true if they
543 // handled the accelerator.
544 virtual bool AcceleratorPressed(const Accelerator& accelerator) {
545 return false;
546 }
547
initial.commit09911bf2008-07-26 23:55:29548 // Returns whether this view currently has the focus.
549 virtual bool HasFocus();
550
551 // Accessibility support
552 // TODO(klink): Move all this out to a AccessibleInfo wrapper class.
553 //
554 // Returns the MSAA default action of the current view. The string returned
555 // describes the default action that will occur when executing
556 // IAccessible::DoDefaultAction. For instance, default action of a button is
557 // 'Press'. Sets the input string appropriately, and returns true if
558 // successful.
559 virtual bool GetAccessibleDefaultAction(std::wstring* action) {
560 return false;
561 }
562
563 // Returns a string containing the mnemonic, or the keyboard shortcut, for a
564 // given control. Sets the input string appropriately, and returns true if
565 // successful.
566 virtual bool GetAccessibleKeyboardShortcut(std::wstring* shortcut) {
567 return false;
568 }
569
570 // Returns a brief, identifying string, containing a unique, readable name of
571 // a given control. Sets the input string appropriately, and returns true if
572 // successful.
573 virtual bool GetAccessibleName(std::wstring* name) { return false; }
574
[email protected]e92070ac2009-04-28 00:12:01575 // Returns the accessibility role of the current view. The role is what
576 // assistive technologies (ATs) use to determine what behavior to expect from
577 // a given control. Sets the input Role appropriately, and returns true if
initial.commit09911bf2008-07-26 23:55:29578 // successful.
[email protected]e92070ac2009-04-28 00:12:01579 virtual bool GetAccessibleRole(AccessibilityTypes::Role* role) {
580 return false;
581 }
initial.commit09911bf2008-07-26 23:55:29582
[email protected]e92070ac2009-04-28 00:12:01583 // Returns the accessibility state of the current view. Sets the input State
584 // appropriately, and returns true if successful.
585 virtual bool GetAccessibleState(AccessibilityTypes::State* state) {
586 return false;
587 }
initial.commit09911bf2008-07-26 23:55:29588
589 // Assigns a keyboard shortcut string description to the given control. Needed
590 // as a View does not know which shortcut will be associated with it until it
591 // is created to be a certain type.
592 virtual void SetAccessibleKeyboardShortcut(const std::wstring& shortcut) {}
593
594 // Assigns a string name to the given control. Needed as a View does not know
595 // which name will be associated with it until it is created to be a
596 // certain type.
597 virtual void SetAccessibleName(const std::wstring& name) {}
598
599 // Returns an instance of a wrapper class implementing the (platform-specific)
600 // accessibility interface for a given View. If one exists, it will be
601 // re-used, otherwise a new instance will be created.
[email protected]fef10642009-03-17 21:17:04602 ViewAccessibilityWrapper* GetViewAccessibilityWrapper();
initial.commit09911bf2008-07-26 23:55:29603
604 // Accessor used to determine if a child view (leaf) has accessibility focus.
605 // Returns NULL if there are no children, or if none of the children has
606 // accessibility focus.
[email protected]c2dacc92008-10-16 23:51:38607 virtual View* GetAccFocusedChildView() { return NULL; }
initial.commit09911bf2008-07-26 23:55:29608
initial.commit09911bf2008-07-26 23:55:29609 // Utility functions
610
611 // Note that the utility coordinate conversions functions always operate on
612 // the mirrored position of the child Views if the parent View uses a
613 // right-to-left UI layout.
614
615 // Convert a point from source coordinate system to dst coordinate system.
616 //
617 // source is a parent or a child of dst, directly or transitively.
618 // If source and dst are not in the same View hierarchy, the result is
619 // undefined.
620 // Source can be NULL in which case it means the screen coordinate system
[email protected]bb515ed2009-01-15 00:53:43621 static void ConvertPointToView(const View* src,
622 const View* dst,
initial.commit09911bf2008-07-26 23:55:29623 gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29624
625 // Convert a point from the coordinate system of a View to that of the
[email protected]a0dde122008-11-21 20:51:20626 // Widget. This is useful for example when sizing HWND children of the
627 // Widget that don't know about the View hierarchy and need to be placed
628 // relative to the Widget that is their parent.
[email protected]2fb6d462009-02-13 18:40:10629 static void ConvertPointToWidget(const View* src, gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29630
[email protected]a0dde122008-11-21 20:51:20631 // Convert a point from a view Widget to a View dest
[email protected]2fb6d462009-02-13 18:40:10632 static void ConvertPointFromWidget(const View* dest, gfx::Point* p);
initial.commit09911bf2008-07-26 23:55:29633
634 // Convert a point from the coordinate system of a View to that of the
635 // screen. This is useful for example when placing popup windows.
[email protected]2fb6d462009-02-13 18:40:10636 static void ConvertPointToScreen(const View* src, gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29637
638 // Event Handlers
639
640 // This method is invoked when the user clicks on this view.
641 // The provided event is in the receiver's coordinate system.
642 //
643 // Return true if you processed the event and want to receive subsequent
644 // MouseDraggged and MouseReleased events. This also stops the event from
645 // bubbling. If you return false, the event will bubble through parent
646 // views.
647 //
648 // If you remove yourself from the tree while processing this, event bubbling
649 // stops as if you returned true, but you will not receive future events.
650 // The return value is ignored in this case.
651 //
652 // Default implementation returns true if a ContextMenuController has been
653 // set, false otherwise. Override as needed.
654 //
655 virtual bool OnMousePressed(const MouseEvent& event);
656
657 // This method is invoked when the user clicked on this control.
658 // and is still moving the mouse with a button pressed.
659 // The provided event is in the receiver's coordinate system.
660 //
661 // Return true if you processed the event and want to receive
662 // subsequent MouseDragged and MouseReleased events.
663 //
664 // Default implementation returns true if a ContextMenuController has been
665 // set, false otherwise. Override as needed.
666 //
667 virtual bool OnMouseDragged(const MouseEvent& event);
668
669 // This method is invoked when the user releases the mouse
670 // button. The event is in the receiver's coordinate system.
671 //
672 // If canceled is true it indicates the mouse press/drag was canceled by a
673 // system/user gesture.
674 //
675 // Default implementation notifies the ContextMenuController is appropriate.
676 // Subclasses that wish to honor the ContextMenuController should invoke
677 // super.
678 virtual void OnMouseReleased(const MouseEvent& event, bool canceled);
679
680 // This method is invoked when the mouse is above this control
681 // The event is in the receiver's coordinate system.
682 //
683 // Default implementation does nothing. Override as needed.
684 virtual void OnMouseMoved(const MouseEvent& e);
685
686 // This method is invoked when the mouse enters this control.
687 //
688 // Default implementation does nothing. Override as needed.
689 virtual void OnMouseEntered(const MouseEvent& event);
690
691 // This method is invoked when the mouse exits this control
692 // The provided event location is always (0, 0)
693 // Default implementation does nothing. Override as needed.
694 virtual void OnMouseExited(const MouseEvent& event);
695
696 // Set the MouseHandler for a drag session.
697 //
698 // A drag session is a stream of mouse events starting
699 // with a MousePressed event, followed by several MouseDragged
700 // events and finishing with a MouseReleased event.
701 //
702 // This method should be only invoked while processing a
703 // MouseDragged or MouseReleased event.
704 //
705 // All further mouse dragged and mouse up events will be sent
706 // the MouseHandler, even if it is reparented to another window.
707 //
708 // The MouseHandler is automatically cleared when the control
709 // comes back from processing the MouseReleased event.
710 //
711 // Note: if the mouse handler is no longer connected to a
712 // view hierarchy, events won't be sent.
713 //
714 virtual void SetMouseHandler(View* new_mouse_handler);
715
716 // Request the keyboard focus. The receiving view will become the
717 // focused view.
718 virtual void RequestFocus();
719
720 // Invoked when a view is about to gain focus
721 virtual void WillGainFocus();
722
723 // Invoked when a view just gained focus.
724 virtual void DidGainFocus();
725
726 // Invoked when a view is about lose focus
727 virtual void WillLoseFocus();
728
729 // Invoked when a view is about to be requested for focus due to the focus
730 // traversal. Reverse is this request was generated going backward
731 // (Shift-Tab).
732 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) { }
733
[email protected]ca13d804c2009-05-14 04:28:07734 // Invoked when a key is pressed before the key event is processed (and
735 // potentially eaten) by the focus manager for tab traversal, accelerators and
736 // other focus related actions.
737 // The default implementation returns false, ensuring that tab traversal and
738 // accelerators processing is performed.
739 // Subclasses should return true if they want to process the key event and not
740 // have it processed as an accelerator (if any) or as a tab traversal (if the
741 // key event is for the TAB key). In that case, OnKeyPressed will
742 // subsequently be invoked for that event.
743 virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& e) {
744 return false;
745 }
746
initial.commit09911bf2008-07-26 23:55:29747 // Invoked when a key is pressed or released.
748 // Subclasser should return true if the event has been processed and false
749 // otherwise. If the event has not been processed, the parent will be given a
750 // chance.
751 virtual bool OnKeyPressed(const KeyEvent& e);
752 virtual bool OnKeyReleased(const KeyEvent& e);
753
initial.commit09911bf2008-07-26 23:55:29754 // Invoked when the user uses the mousewheel. Implementors should return true
755 // if the event has been processed and false otherwise. This message is sent
756 // if the view is focused. If the event has not been processed, the parent
757 // will be given a chance.
758 virtual bool OnMouseWheel(const MouseWheelEvent& e);
759
760 // Drag and drop functions.
761
762 // Set/get the DragController. See description of DragController for more
763 // information.
764 void SetDragController(DragController* drag_controller);
765 DragController* GetDragController();
766
767 // During a drag and drop session when the mouse moves the view under the
[email protected]134c47b92009-08-19 03:33:44768 // mouse is queried for the drop types it supports by way of the
769 // GetDropFormats methods. If the view returns true and the drag site can
770 // provide data in one of the formats, the view is asked if the drop data
771 // is required before any other drop events are sent. Once the
772 // data is available the view is asked if it supports the drop (by way of
773 // the CanDrop method). If a view returns true from CanDrop,
initial.commit09911bf2008-07-26 23:55:29774 // OnDragEntered is sent to the view when the mouse first enters the view,
775 // as the mouse moves around within the view OnDragUpdated is invoked.
776 // If the user releases the mouse over the view and OnDragUpdated returns a
777 // valid drop, then OnPerformDrop is invoked. If the mouse moves outside the
778 // view or over another view that wants the drag, OnDragExited is invoked.
779 //
780 // Similar to mouse events, the deepest view under the mouse is first checked
781 // if it supports the drop (Drop). If the deepest view under
782 // the mouse does not support the drop, the ancestors are walked until one
783 // is found that supports the drop.
784
[email protected]134c47b92009-08-19 03:33:44785 // Override and return the set of formats that can be dropped on this view.
786 // |formats| is a bitmask of the formats defined bye OSExchangeData::Format.
787 // The default implementation returns false, which means the view doesn't
788 // support dropping.
789 virtual bool GetDropFormats(
790 int* formats,
791 std::set<OSExchangeData::CustomFormat>* custom_formats);
792
793 // Override and return true if the data must be available before any drop
794 // methods should be invoked. The default is false.
795 virtual bool AreDropTypesRequired();
796
initial.commit09911bf2008-07-26 23:55:29797 // A view that supports drag and drop must override this and return true if
798 // data contains a type that may be dropped on this view.
799 virtual bool CanDrop(const OSExchangeData& data);
800
801 // OnDragEntered is invoked when the mouse enters this view during a drag and
802 // drop session and CanDrop returns true. This is immediately
803 // followed by an invocation of OnDragUpdated, and eventually one of
804 // OnDragExited or OnPerformDrop.
805 virtual void OnDragEntered(const DropTargetEvent& event);
806
807 // Invoked during a drag and drop session while the mouse is over the view.
808 // This should return a bitmask of the DragDropTypes::DragOperation supported
809 // based on the location of the event. Return 0 to indicate the drop should
810 // not be accepted.
811 virtual int OnDragUpdated(const DropTargetEvent& event);
812
813 // Invoked during a drag and drop session when the mouse exits the views, or
814 // when the drag session was canceled and the mouse was over the view.
815 virtual void OnDragExited();
816
817 // Invoked during a drag and drop session when OnDragUpdated returns a valid
818 // operation and the user release the mouse.
819 virtual int OnPerformDrop(const DropTargetEvent& event);
820
821 // Returns true if the mouse was dragged enough to start a drag operation.
822 // delta_x and y are the distance the mouse was dragged.
823 static bool ExceededDragThreshold(int delta_x, int delta_y);
824
825 // This method is the main entry point to process paint for this
826 // view and its children. This method is called by the painting
827 // system. You should call this only if you want to draw a sub tree
828 // inside a custom graphics.
829 // To customize painting override either the Paint or PaintChildren method,
830 // not this one.
[email protected]82522512009-05-15 07:37:29831 virtual void ProcessPaint(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29832
833 // Paint the View's child Views, in reverse order.
[email protected]82522512009-05-15 07:37:29834 virtual void PaintChildren(gfx::Canvas* canvas);
initial.commit09911bf2008-07-26 23:55:29835
836 // Sets the ContextMenuController. Setting this to non-null makes the View
837 // process mouse events.
838 void SetContextMenuController(ContextMenuController* menu_controller);
839 ContextMenuController* GetContextMenuController() {
840 return context_menu_controller_;
841 }
842
[email protected]042811c2008-10-31 21:31:34843 // Provides default implementation for context menu handling. The default
844 // implementation calls the ShowContextMenu of the current
845 // ContextMenuController (if it is not NULL). Overridden in subclassed views
846 // to provide right-click menu display triggerd by the keyboard (i.e. for the
847 // Chrome toolbar Back and Forward buttons). No source needs to be specified,
848 // as it is always equal to the current View.
849 virtual void ShowContextMenu(int x,
850 int y,
851 bool is_mouse_gesture);
852
[email protected]9a3f0ac22008-11-14 03:24:02853 // The background object is owned by this object and may be NULL.
854 void set_background(Background* b) { background_.reset(b); }
855 const Background* background() const { return background_.get(); }
initial.commit09911bf2008-07-26 23:55:29856
[email protected]9a3f0ac22008-11-14 03:24:02857 // The border object is owned by this object and may be NULL.
858 void set_border(Border* b) { border_.reset(b); }
859 const Border* border() const { return border_.get(); }
initial.commit09911bf2008-07-26 23:55:29860
861 // Returns the insets of the current border. If there is no border an empty
862 // insets is returned.
[email protected]a37bea82009-04-22 23:02:15863 virtual gfx::Insets GetInsets() const;
initial.commit09911bf2008-07-26 23:55:29864
865 // Return the cursor that should be used for this view or NULL if
866 // the default cursor should be used. The provided point is in the
[email protected]9abf8dd62009-06-04 06:40:42867 // receiver's coordinate system. The caller is responsible for managing the
868 // lifetime of the returned object, though that lifetime may vary from
869 // platform to platform. On Windows, the cursor is a shared resource but in
870 // Gtk, the framework destroys the returned cursor after setting it.
871 virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type,
872 int x,
873 int y);
initial.commit09911bf2008-07-26 23:55:29874
875 // Convenience to test whether a point is within this view's bounds
[email protected]613b8062008-10-14 23:45:09876 virtual bool HitTest(const gfx::Point& l) const;
initial.commit09911bf2008-07-26 23:55:29877
878 // Gets the tooltip for this View. If the View does not have a tooltip,
879 // return false. If the View does have a tooltip, copy the tooltip into
880 // the supplied string and return true.
881 // Any time the tooltip text that a View is displaying changes, it must
882 // invoke TooltipTextChanged.
883 // The x/y provide the coordinates of the mouse (relative to this view).
884 virtual bool GetTooltipText(int x, int y, std::wstring* tooltip);
885
886 // Returns the location (relative to this View) for the text on the tooltip
887 // to display. If false is returned (the default), the tooltip is placed at
888 // a default position.
[email protected]0a1d36b22008-10-17 19:33:09889 virtual bool GetTooltipTextOrigin(int x, int y, gfx::Point* loc);
initial.commit09911bf2008-07-26 23:55:29890
891 // Set whether this view is owned by its parent. A view that is owned by its
892 // parent is automatically deleted when the parent is deleted. The default is
893 // true. Set to false if the view is owned by another object and should not
894 // be deleted by its parent.
[email protected]09fe9492009-11-07 02:23:06895 void set_parent_owned(bool is_parent_owned) {
896 is_parent_owned_ = is_parent_owned;
897 }
initial.commit09911bf2008-07-26 23:55:29898
[email protected]09fe9492009-11-07 02:23:06899 // Return whether a view is owned by its parent.
900 bool IsParentOwned() const { return is_parent_owned_; }
initial.commit09911bf2008-07-26 23:55:29901
902 // Return the receiving view's class name. A view class is a string which
903 // uniquely identifies the view class. It is intended to be used as a way to
904 // find out during run time if a view can be safely casted to a specific view
905 // subclass. The default implementation returns kViewClassName.
906 virtual std::string GetClassName() const;
907
[email protected]5c2b98b2009-03-09 20:55:54908 // Returns the first ancestor, starting at this, whose class name is |name|.
909 // Returns null if no ancestor has the class name |name|.
910 View* GetAncestorWithClassName(const std::string& name);
911
initial.commit09911bf2008-07-26 23:55:29912 // Returns the visible bounds of the receiver in the receivers coordinate
913 // system.
914 //
915 // When traversing the View hierarchy in order to compute the bounds, the
916 // function takes into account the mirroring setting for each View and
917 // therefore it will return the mirrored version of the visible bounds if
918 // need be.
919 gfx::Rect GetVisibleBounds();
920
921 // Subclasses that contain traversable children that are not directly
922 // accessible through the children hierarchy should return the associated
923 // FocusTraversable for the focus traversal to work properly.
924 virtual FocusTraversable* GetFocusTraversable() { return NULL; }
925
926#ifndef NDEBUG
927 // Debug method that logs the view hierarchy to the output.
928 void PrintViewHierarchy();
929
930 // Debug method that logs the focus traversal hierarchy to the output.
931 void PrintFocusHierarchy();
932#endif
933
934 // The following methods are used by ScrollView to determine the amount
935 // to scroll relative to the visible bounds of the view. For example, a
936 // return value of 10 indicates the scrollview should scroll 10 pixels in
937 // the appropriate direction.
938 //
939 // Each method takes the following parameters:
940 //
941 // is_horizontal: if true, scrolling is along the horizontal axis, otherwise
942 // the vertical axis.
943 // is_positive: if true, scrolling is by a positive amount. Along the
944 // vertical axis scrolling by a positive amount equates to
945 // scrolling down.
946 //
947 // The return value should always be positive and gives the number of pixels
948 // to scroll. ScrollView interprets a return value of 0 (or negative)
949 // to scroll by a default amount.
950 //
951 // See VariableRowHeightScrollHelper and FixedRowHeightScrollHelper for
952 // implementations of common cases.
953 virtual int GetPageScrollIncrement(ScrollView* scroll_view,
954 bool is_horizontal, bool is_positive);
955 virtual int GetLineScrollIncrement(ScrollView* scroll_view,
956 bool is_horizontal, bool is_positive);
957
[email protected]4a190632009-05-09 01:07:42958 // Get the theme provider from the parent widget.
[email protected]45da6c72009-10-28 20:45:42959 ThemeProvider* GetThemeProvider() const;
[email protected]4a190632009-05-09 01:07:42960
initial.commit09911bf2008-07-26 23:55:29961 protected:
initial.commit09911bf2008-07-26 23:55:29962 // The id of this View. Used to find this View.
963 int id_;
964
965 // The group of this view. Some view subclasses use this id to find other
966 // views of the same group. For example radio button uses this information
967 // to find other radio buttons.
968 int group_;
969
[email protected]32670b02009-03-03 00:28:00970 // Called when the UI theme has changed, overriding allows individual Views to
971 // do special cleanup and processing (such as dropping resource caches).
972 // Subclasses that override this method must call the base class
973 // implementation to ensure child views are processed.
974 // Can only be called by subclasses. To dispatch a theme changed notification,
975 // call this method on the RootView.
976 virtual void ThemeChanged();
977
initial.commit09911bf2008-07-26 23:55:29978#ifndef NDEBUG
979 // Returns true if the View is currently processing a paint.
980 virtual bool IsProcessingPaint() const;
981#endif
982
[email protected]f704ee72008-11-10 21:31:59983 // Returns the location, in screen coordinates, to show the context menu at
984 // when the context menu is shown from the keyboard. This implementation
985 // returns the middle of the visible region of this view.
986 //
987 // This method is invoked when the context menu is shown by way of the
988 // keyboard.
989 virtual gfx::Point GetKeyboardContextMenuLocation();
990
[email protected]82739cf2008-09-16 00:37:56991 // Called by HitTest to see if this View has a custom hit test mask. If the
992 // return value is true, GetHitTestMask will be called to obtain the mask.
993 // Default value is false, in which case the View will hit-test against its
994 // bounds.
995 virtual bool HasHitTestMask() const;
996
997 // Called by HitTest to retrieve a mask for hit-testing against. Subclasses
998 // override to provide custom shaped hit test regions.
999 virtual void GetHitTestMask(gfx::Path* mask) const;
1000
initial.commit09911bf2008-07-26 23:55:291001 // This method is invoked when the tree changes.
1002 //
1003 // When a view is removed, it is invoked for all children and grand
1004 // children. For each of these views, a notification is sent to the
1005 // view and all parents.
1006 //
1007 // When a view is added, a notification is sent to the view, all its
1008 // parents, and all its children (and grand children)
1009 //
1010 // Default implementation does nothing. Override to perform operations
1011 // required when a view is added or removed from a view hierarchy
1012 //
1013 // parent is the new or old parent. Child is the view being added or
1014 // removed.
1015 //
1016 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
1017
1018 // When SetVisible() changes the visibility of a view, this method is
1019 // invoked for that view as well as all the children recursively.
1020 virtual void VisibilityChanged(View* starting_from, bool is_visible);
1021
[email protected]7ccc52b72009-05-08 21:09:111022 // Called when the preferred size of a child view changed. This gives the
1023 // parent an opportunity to do a fresh layout if that makes sense.
1024 virtual void ChildPreferredSizeChanged(View* child) {}
1025
1026 // Simply calls ChildPreferredSizeChanged on the parent if there is one.
1027 virtual void PreferredSizeChanged();
1028
initial.commit09911bf2008-07-26 23:55:291029 // Views must invoke this when the tooltip text they are to display changes.
1030 void TooltipTextChanged();
1031
initial.commit09911bf2008-07-26 23:55:291032 // Sets whether this view wants notification when its visible bounds relative
1033 // to the root view changes. If true, this view is notified any time the
1034 // origin of one its ancestors changes, or the portion of the bounds not
1035 // obscured by ancestors changes. The default is false.
1036 void SetNotifyWhenVisibleBoundsInRootChanges(bool value);
1037 bool GetNotifyWhenVisibleBoundsInRootChanges();
1038
1039 // Notification that this views visible bounds, relative to the RootView
1040 // has changed. The visible bounds corresponds to the region of the
1041 // view not obscured by other ancestors.
1042 virtual void VisibleBoundsInRootChanged() {}
1043
1044 // Sets the keyboard focus to this View. The correct way to set the focus is
1045 // to call RequestFocus() on the view. This method is called when the focus is
1046 // set and gives an opportunity to subclasses to perform any extra focus steps
1047 // (for example native component set the native focus on their native
1048 // component). The default behavior is to set the native focus on the root
[email protected]a0dde122008-11-21 20:51:201049 // Widget, which is what is appropriate for views that have no native window
1050 // associated with them (so the root view gets the keyboard messages).
initial.commit09911bf2008-07-26 23:55:291051 virtual void Focus();
1052
initial.commit09911bf2008-07-26 23:55:291053 // These are cover methods that invoke the method of the same name on
1054 // the DragController. Subclasses may wish to override rather than install
1055 // a DragController.
1056 // See DragController for a description of these methods.
1057 virtual int GetDragOperations(int press_x, int press_y);
1058 virtual void WriteDragData(int press_x, int press_y, OSExchangeData* data);
1059
1060 // Invoked from DoDrag after the drag completes. This implementation does
1061 // nothing, and is intended for subclasses to do cleanup.
1062 virtual void OnDragDone();
1063
1064 // Returns whether we're in the middle of a drag session that was initiated
1065 // by us.
1066 bool InDrag();
1067
[email protected]253a39a2009-05-29 20:45:131068 // Returns how much the mouse needs to move in one direction to start a
1069 // drag. These methods cache in a platform-appropriate way. These values are
1070 // used by the public static method ExceededDragThreshold().
1071 static int GetHorizontalDragThreshold();
1072 static int GetVerticalDragThreshold();
1073
initial.commit09911bf2008-07-26 23:55:291074 // Whether this view is enabled.
1075 bool enabled_;
1076
1077 // Whether the view can be focused.
1078 bool focusable_;
1079
1080 private:
1081 friend class RootView;
1082 friend class FocusManager;
1083 friend class ViewStorage;
1084
1085 // Used to track a drag. RootView passes this into
1086 // ProcessMousePressed/Dragged.
1087 struct DragInfo {
1088 // Sets possible_drag to false and start_x/y to 0. This is invoked by
1089 // RootView prior to invoke ProcessMousePressed.
1090 void Reset();
1091
1092 // Sets possible_drag to true and start_x/y to the specified coordinates.
1093 // This is invoked by the target view if it detects the press may generate
1094 // a drag.
1095 void PossibleDrag(int x, int y);
1096
1097 // Whether the press may generate a drag.
1098 bool possible_drag;
1099
1100 // Coordinates of the mouse press.
1101 int start_x;
1102 int start_y;
1103 };
1104
1105 // RootView invokes these. These in turn invoke the appropriate OnMouseXXX
1106 // method. If a drag is detected, DoDrag is invoked.
1107 bool ProcessMousePressed(const MouseEvent& e, DragInfo* drop_info);
1108 bool ProcessMouseDragged(const MouseEvent& e, DragInfo* drop_info);
1109 void ProcessMouseReleased(const MouseEvent& e, bool canceled);
1110
1111 // Starts a drag and drop operation originating from this view. This invokes
1112 // WriteDragData to write the data and GetDragOperations to determine the
1113 // supported drag operations. When done, OnDragDone is invoked.
[email protected]c2dacc92008-10-16 23:51:381114 void DoDrag(const MouseEvent& e, int press_x, int press_y);
initial.commit09911bf2008-07-26 23:55:291115
initial.commit09911bf2008-07-26 23:55:291116 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true,
1117 // the next and previous focusable views of views pointing to this view are
1118 // updated. If |update_tool_tip| is true, the tooltip is updated. If
1119 // |delete_removed_view| is true, the view is also deleted (if it is parent
1120 // owned).
1121 void DoRemoveChildView(View* view,
1122 bool update_focus_cycle,
1123 bool update_tool_tip,
1124 bool delete_removed_view);
1125
1126 // Sets the parent View. This is called automatically by AddChild and is
1127 // thus private.
[email protected]054e3fd2009-09-14 19:48:051128 void SetParent(View* parent);
initial.commit09911bf2008-07-26 23:55:291129
1130 // Call ViewHierarchyChanged for all child views on all parents
1131 void PropagateRemoveNotifications(View* parent);
1132
1133 // Call ViewHierarchyChanged for all children
1134 void PropagateAddNotifications(View* parent, View* child);
1135
1136 // Call VisibilityChanged() recursively for all children.
1137 void PropagateVisibilityNotifications(View* from, bool is_visible);
1138
1139 // Takes care of registering/unregistering accelerators if
1140 // |register_accelerators| true and calls ViewHierarchyChanged().
1141 void ViewHierarchyChangedImpl(bool register_accelerators,
[email protected]bb515ed2009-01-15 00:53:431142 bool is_add,
1143 View* parent,
1144 View* child);
initial.commit09911bf2008-07-26 23:55:291145
1146 // This is the actual implementation for ConvertPointToView()
1147 // Attempts a parent -> child conversion and then a
1148 // child -> parent conversion if try_other_direction is true
[email protected]bb515ed2009-01-15 00:53:431149 static void ConvertPointToView(const View* src,
1150 const View* dst,
initial.commit09911bf2008-07-26 23:55:291151 gfx::Point* point,
1152 bool try_other_direction);
1153
[email protected]a0dde122008-11-21 20:51:201154 // Propagates UpdateTooltip() to the TooltipManager for the Widget.
initial.commit09911bf2008-07-26 23:55:291155 // This must be invoked any time the View hierarchy changes in such a way
1156 // the view under the mouse differs. For example, if the bounds of a View is
1157 // changed, this is invoked. Similarly, as Views are added/removed, this
1158 // is invoked.
1159 void UpdateTooltip();
1160
1161 // Recursively descends through all descendant views,
1162 // registering/unregistering all views that want visible bounds in root
1163 // view notification.
1164 static void RegisterChildrenForVisibleBoundsNotification(RootView* root,
1165 View* view);
1166 static void UnregisterChildrenForVisibleBoundsNotification(RootView* root,
1167 View* view);
1168
1169 // Adds/removes view to the list of descendants that are notified any time
1170 // this views location and possibly size are changed.
1171 void AddDescendantToNotify(View* view);
1172 void RemoveDescendantToNotify(View* view);
1173
1174 // Initialize the previous/next focusable views of the specified view relative
1175 // to the view at the specified index.
1176 void InitFocusSiblings(View* view, int index);
1177
1178 // Actual implementation of PrintFocusHierarchy.
1179 void PrintViewHierarchyImp(int indent);
1180 void PrintFocusHierarchyImp(int indent);
1181
[email protected]71421c3f2009-06-06 00:41:441182 // Registers this view's keyboard accelerators that are not registered to
1183 // FocusManager yet, if possible.
1184 void RegisterPendingAccelerators();
1185
1186 // Unregisters all the keyboard accelerators associated with this view.
initial.commit09911bf2008-07-26 23:55:291187 void UnregisterAccelerators();
1188
[email protected]80f8b9f2008-10-16 18:17:471189 // This View's bounds in the parent coordinate system.
1190 gfx::Rect bounds_;
1191
initial.commit09911bf2008-07-26 23:55:291192 // This view's parent
[email protected]054e3fd2009-09-14 19:48:051193 View* parent_;
initial.commit09911bf2008-07-26 23:55:291194
1195 // This view's children.
1196 typedef std::vector<View*> ViewList;
1197 ViewList child_views_;
1198
initial.commit09911bf2008-07-26 23:55:291199 // The View's LayoutManager defines the sizing heuristics applied to child
1200 // Views. The default is absolute positioning according to bounds_.
1201 scoped_ptr<LayoutManager> layout_manager_;
1202
1203 // Visible state
1204 bool is_visible_;
1205
1206 // Background
[email protected]9a3f0ac22008-11-14 03:24:021207 scoped_ptr<Background> background_;
initial.commit09911bf2008-07-26 23:55:291208
1209 // Border.
[email protected]9a3f0ac22008-11-14 03:24:021210 scoped_ptr<Border> border_;
initial.commit09911bf2008-07-26 23:55:291211
1212 // Whether this view is owned by its parent.
1213 bool is_parent_owned_;
1214
1215 // See SetNotifyWhenVisibleBoundsInRootChanges.
1216 bool notify_when_visible_bounds_in_root_changes_;
1217
1218 // Whether or not RegisterViewForVisibleBoundsNotification on the RootView
1219 // has been invoked.
1220 bool registered_for_visible_bounds_notification_;
1221
1222 // List of descendants wanting notification when their visible bounds change.
1223 scoped_ptr<ViewList> descendants_to_notify_;
1224
1225 // Next view to be focused when the Tab key is pressed.
1226 View* next_focusable_view_;
1227
1228 // Next view to be focused when the Shift-Tab key combination is pressed.
1229 View* previous_focusable_view_;
1230
[email protected]71421c3f2009-06-06 00:41:441231 // The list of accelerators. List elements in the range
1232 // [0, registered_accelerator_count_) are already registered to FocusManager,
1233 // and the rest are not yet.
[email protected]1eb89e82008-08-15 12:27:031234 scoped_ptr<std::vector<Accelerator> > accelerators_;
[email protected]4bd23f32009-06-08 20:59:191235 size_t registered_accelerator_count_;
initial.commit09911bf2008-07-26 23:55:291236
initial.commit09911bf2008-07-26 23:55:291237 // The menu controller.
1238 ContextMenuController* context_menu_controller_;
1239
[email protected]6ff244f2009-01-20 20:38:081240#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291241 // The accessibility implementation for this View.
[email protected]fef10642009-03-17 21:17:041242 scoped_ptr<ViewAccessibilityWrapper> accessibility_;
[email protected]6ff244f2009-01-20 20:38:081243#endif
initial.commit09911bf2008-07-26 23:55:291244
1245 DragController* drag_controller_;
1246
1247 // Indicates whether or not the view is going to be mirrored (that is, use a
1248 // right-to-left UI layout) if the locale's language is a right-to-left
1249 // language like Arabic or Hebrew.
1250 bool ui_mirroring_is_enabled_for_rtl_languages_;
1251
[email protected]82522512009-05-15 07:37:291252 // Indicates whether or not the gfx::Canvas object passed to View::Paint()
initial.commit09911bf2008-07-26 23:55:291253 // is going to be flipped horizontally (using the appropriate transform) on
1254 // right-to-left locales for this View.
1255 bool flip_canvas_on_paint_for_rtl_ui_;
1256
[email protected]1eb89e82008-08-15 12:27:031257 DISALLOW_COPY_AND_ASSIGN(View);
initial.commit09911bf2008-07-26 23:55:291258};
1259
[email protected]c2dacc92008-10-16 23:51:381260} // namespace views
initial.commit09911bf2008-07-26 23:55:291261
[email protected]2362e4f2009-05-08 00:34:051262#endif // VIEWS_VIEW_H_