blob: 86511834f335c8cf49c92b33cafc7e6001417542 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]1eb89e82008-08-15 12:27:035#ifndef CHROME_VIEWS_VIEW_H_
6#define CHROME_VIEWS_VIEW_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]8c117712009-01-13 12:26:468#include "build/build_config.h"
9
10#if defined(OS_WIN)
[email protected]1bc83062009-02-06 00:16:3711#include <atlbase.h>
12#include <atlapp.h>
13#include <atlmisc.h>
[email protected]8c117712009-01-13 12:26:4614#endif // defined(OS_WIN)
[email protected]bc944fd2008-10-17 20:20:3015
[email protected]1bc83062009-02-06 00:16:3716#include <algorithm>
initial.commit09911bf2008-07-26 23:55:2917#include <map>
[email protected]1bc83062009-02-06 00:16:3718#include <string>
initial.commit09911bf2008-07-26 23:55:2919#include <vector>
20
initial.commit09911bf2008-07-26 23:55:2921#include "base/gfx/rect.h"
22#include "base/scoped_ptr.h"
initial.commit09911bf2008-07-26 23:55:2923#include "chrome/views/accelerator.h"
[email protected]9a3f0ac22008-11-14 03:24:0224#include "chrome/views/background.h"
25#include "chrome/views/border.h"
initial.commit09911bf2008-07-26 23:55:2926
[email protected]1eb89e82008-08-15 12:27:0327namespace gfx {
28class Insets;
[email protected]82739cf2008-09-16 00:37:5629class Path;
[email protected]1eb89e82008-08-15 12:27:0330}
31
32class AccessibleWrapper;
initial.commit09911bf2008-07-26 23:55:2933class ChromeCanvas;
34class OSExchangeData;
initial.commit09911bf2008-07-26 23:55:2935
[email protected]c2dacc92008-10-16 23:51:3836namespace views {
initial.commit09911bf2008-07-26 23:55:2937
38class Background;
39class Border;
40class FocusManager;
41class FocusTraversable;
42class LayoutManager;
43class RestoreFocusTask;
44class RootView;
45class ScrollView;
[email protected]a0dde122008-11-21 20:51:2046class Widget;
initial.commit09911bf2008-07-26 23:55:2947
48// ContextMenuController is responsible for showing the context menu for a
49// View. To use a ContextMenuController invoke SetContextMenuController on a
50// View. When the appropriate user gesture occurs ShowContextMenu is invoked
51// on the ContextMenuController.
52//
53// Setting a ContextMenuController on a view makes the view process mouse
54// events.
55//
56// It is up to subclasses that do their own mouse processing to invoke
57// the appropriate ContextMenuController method, typically by invoking super's
58// implementation for mouse processing.
59//
60class ContextMenuController {
61 public:
62 // Invoked to show the context menu for the source view. If is_mouse_gesture
63 // is true, the x/y coordinate are the location of the mouse. If
64 // is_mouse_gesture is false, this method was not invoked by a mouse gesture
65 // and x/y is the recommended location to show the menu at.
66 //
67 // x/y is in screen coordinates.
68 virtual void ShowContextMenu(View* source,
69 int x,
70 int y,
71 bool is_mouse_gesture) = 0;
72};
73
74// DragController is responsible for writing drag data for a view, as well as
75// supplying the supported drag operations. Use DragController if you don't
76// want to subclass.
77
78class DragController {
79 public:
80 // Writes the data for the drag.
81 virtual void WriteDragData(View* sender,
82 int press_x,
83 int press_y,
84 OSExchangeData* data) = 0;
85
86 // Returns the supported drag operations (see DragDropTypes for possible
87 // values). A drag is only started if this returns a non-zero value.
88 virtual int GetDragOperations(View* sender, int x, int y) = 0;
89};
90
91
92/////////////////////////////////////////////////////////////////////////////
93//
94// View class
95//
[email protected]c2dacc92008-10-16 23:51:3896// A View is a rectangle within the views View hierarchy. It is the base
[email protected]1bc83062009-02-06 00:16:3797// class for all Views.
initial.commit09911bf2008-07-26 23:55:2998//
99// A View is a container of other Views (there is no such thing as a Leaf
100// View - makes code simpler, reduces type conversion headaches, design
101// mistakes etc)
102//
103// The View contains basic properties for sizing (bounds), layout (flex,
104// orientation, etc), painting of children and event dispatch.
105//
106// The View also uses a simple Box Layout Manager similar to XUL's
107// SprocketLayout system. Alternative Layout Managers implementing the
108// LayoutManager interface can be used to lay out children if required.
109//
110// It is up to the subclass to implement Painting and storage of subclass -
111// specific properties and functionality.
112//
113/////////////////////////////////////////////////////////////////////////////
114class View : public AcceleratorTarget {
115 public:
116
117 // Used in EnumerateFloatingViews() to specify which floating view to
118 // retrieve.
119 enum FloatingViewPosition {
120 FIRST = 0,
121 NEXT,
122 PREVIOUS,
123 LAST,
124 CURRENT
125 };
126
[email protected]6f3bb6c2008-09-17 22:25:33127 // Used in the versions of GetBounds() and x() that take a transformation
initial.commit09911bf2008-07-26 23:55:29128 // parameter in order to determine whether or not to take into account the
129 // mirroring setting of the View when returning bounds positions.
130 enum PositionMirroringSettings {
131 IGNORE_MIRRORING_TRANSFORMATION = 0,
132 APPLY_MIRRORING_TRANSFORMATION
133 };
134
135 // The view class name.
136 static char kViewClassName[];
137
138 View();
139 virtual ~View();
140
141 // Sizing functions
142
143 // Get the bounds of the View, relative to the parent. Essentially, this
144 // function returns the bounds_ rectangle.
145 //
146 // This is the function subclasses should use whenever they need to obtain
147 // the bounds of one of their child views (for example, when implementing
148 // View::Layout()).
[email protected]0d8ea702008-10-14 17:03:07149 // TODO(beng): Convert |bounds_| to a gfx::Rect.
[email protected]80f8b9f2008-10-16 18:17:47150 gfx::Rect bounds() const { return bounds_; }
151
152 // Get the size of the View.
153 gfx::Size size() const { return bounds_.size(); }
initial.commit09911bf2008-07-26 23:55:29154
155 // Return the bounds of the View, relative to the parent. If
156 // |settings| is IGNORE_MIRRORING_TRANSFORMATION, the function returns the
157 // bounds_ rectangle. If |settings| is APPLY_MIRRORING_SETTINGS AND the
158 // parent View is using a right-to-left UI layout, then the function returns
159 // a shifted version of the bounds_ rectangle that represents the mirrored
160 // View bounds.
161 //
162 // NOTE: in the vast majority of the cases, the mirroring implementation is
163 // transparent to the View subclasses and therefore you should use the
164 // version of GetBounds() which does not take a transformation settings
165 // parameter.
[email protected]0d8ea702008-10-14 17:03:07166 gfx::Rect GetBounds(PositionMirroringSettings settings) const;
initial.commit09911bf2008-07-26 23:55:29167
168 // Set the bounds in the parent's coordinate system.
[email protected]80f8b9f2008-10-16 18:17:47169 void SetBounds(const gfx::Rect& bounds);
170 void SetBounds(int x, int y, int width, int height) {
171 SetBounds(gfx::Rect(x, y, std::max(0, width), std::max(0, height)));
172 }
[email protected]6f3bb6c2008-09-17 22:25:33173 void SetX(int x) { SetBounds(x, y(), width(), height()); }
174 void SetY(int y) { SetBounds(x(), y, width(), height()); }
initial.commit09911bf2008-07-26 23:55:29175
176 // Returns the left coordinate of the View, relative to the parent View,
[email protected]80f8b9f2008-10-16 18:17:47177 // which is the value of bounds_.x().
initial.commit09911bf2008-07-26 23:55:29178 //
179 // This is the function subclasses should use whenever they need to obtain
180 // the left position of one of their child views (for example, when
181 // implementing View::Layout()).
[email protected]0a1d36b22008-10-17 19:33:09182 // This is equivalent to GetX(IGNORE_MIRRORING_TRANSFORMATION), but
183 // inlinable.
184 int x() const { return bounds_.x(); }
185 int y() const { return bounds_.y(); }
186 int width() const { return bounds_.width(); }
187 int height() const { return bounds_.height(); }
initial.commit09911bf2008-07-26 23:55:29188
189 // Return the left coordinate of the View, relative to the parent. If
190 // |settings| is IGNORE_MIRRORING_SETTINGS, the function returns the value of
[email protected]80f8b9f2008-10-16 18:17:47191 // bounds_.x(). If |settings| is APPLY_MIRRORING_SETTINGS AND the parent
initial.commit09911bf2008-07-26 23:55:29192 // View is using a right-to-left UI layout, then the function returns the
[email protected]80f8b9f2008-10-16 18:17:47193 // mirrored value of bounds_.x().
initial.commit09911bf2008-07-26 23:55:29194 //
195 // NOTE: in the vast majority of the cases, the mirroring implementation is
196 // transparent to the View subclasses and therefore you should use the
[email protected]6f3bb6c2008-09-17 22:25:33197 // paremeterless version of x() when you need to get the X
initial.commit09911bf2008-07-26 23:55:29198 // coordinate of a child View.
199 int GetX(PositionMirroringSettings settings) const;
200
initial.commit09911bf2008-07-26 23:55:29201 // Return this control local bounds. If include_border is true, local bounds
[email protected]6f3bb6c2008-09-17 22:25:33202 // is the rectangle {0, 0, width(), height()}, otherwise, it does not
initial.commit09911bf2008-07-26 23:55:29203 // include the area where the border (if any) is painted.
[email protected]80f8b9f2008-10-16 18:17:47204 gfx::Rect GetLocalBounds(bool include_border) const;
initial.commit09911bf2008-07-26 23:55:29205
206 // Get the position of the View, relative to the parent.
207 //
208 // Note that if the parent uses right-to-left UI layout, then the mirrored
[email protected]6f3bb6c2008-09-17 22:25:33209 // position of this View is returned. Use x()/y() if you want to ignore
initial.commit09911bf2008-07-26 23:55:29210 // mirroring.
[email protected]0a1d36b22008-10-17 19:33:09211 gfx::Point GetPosition() const;
initial.commit09911bf2008-07-26 23:55:29212
213 // Get the size the View would like to be, if enough space were available.
[email protected]154f8bc2008-10-15 18:02:30214 virtual gfx::Size GetPreferredSize();
initial.commit09911bf2008-07-26 23:55:29215
216 // Convenience method that sizes this view to its preferred size.
217 void SizeToPreferredSize();
218
219 // Gets the minimum size of the view. View's implementation invokes
220 // GetPreferredSize.
[email protected]154f8bc2008-10-15 18:02:30221 virtual gfx::Size GetMinimumSize();
initial.commit09911bf2008-07-26 23:55:29222
223 // Return the height necessary to display this view with the provided width.
224 // View's implementation returns the value from getPreferredSize.cy.
225 // Override if your View's preferred height depends upon the width (such
226 // as with Labels).
227 virtual int GetHeightForWidth(int w);
228
229 // This method is invoked when this object size or position changes.
230 // The default implementation does nothing.
[email protected]80f8b9f2008-10-16 18:17:47231 virtual void DidChangeBounds(const gfx::Rect& previous,
232 const gfx::Rect& current);
initial.commit09911bf2008-07-26 23:55:29233
234 // Set whether the receiving view is visible. Painting is scheduled as needed
235 virtual void SetVisible(bool flag);
236
237 // Return whether a view is visible
238 virtual bool IsVisible() const { return is_visible_; }
239
240 // Return whether a view and its ancestors are visible. Returns true if the
241 // path from this view to the root view is visible.
242 virtual bool IsVisibleInRootView() const;
243
244 // Set whether this view is enabled. A disabled view does not receive keyboard
245 // or mouse inputs. If flag differs from the current value, SchedulePaint is
246 // invoked.
247 virtual void SetEnabled(bool flag);
248
249 // Returns whether the view is enabled.
250 virtual bool IsEnabled() const;
251
252 // Set whether this view is hottracked. A disabled view cannot be hottracked.
253 // If flag differs from the current value, SchedulePaint is invoked.
254 virtual void SetHotTracked(bool flag);
255
256 // Returns whether the view is hot-tracked.
257 virtual bool IsHotTracked() const { return false; }
258
259 // Returns whether the view is pushed.
260 virtual bool IsPushed() const { return false; }
261
262 // Scrolls the specified region, in this View's coordinate system, to be
263 // visible. View's implementation passes the call onto the parent View (after
264 // adjusting the coordinates). It is up to views that only show a portion of
265 // the child view, such as Viewport, to override appropriately.
266 virtual void ScrollRectToVisible(int x, int y, int width, int height);
267
268 // Layout functions
269
270 // Lay out the child Views (set their bounds based on sizing heuristics
271 // specific to the current Layout Manager)
272 virtual void Layout();
273
274 // Gets/Sets the Layout Manager used by this view to size and place its
275 // children.
276 // The LayoutManager is owned by the View and is deleted when the view is
277 // deleted, or when a new LayoutManager is installed.
278 LayoutManager* GetLayoutManager() const;
279 void SetLayoutManager(LayoutManager* layout);
280
281 // Right-to-left UI layout functions
282
283 // Indicates whether the UI layout for this view is right-to-left. The view
284 // has an RTL UI layout if RTL hasn't been disabled for the view and if the
285 // locale's language is an RTL language.
[email protected]1eb89e82008-08-15 12:27:03286 bool UILayoutIsRightToLeft() const;
initial.commit09911bf2008-07-26 23:55:29287
288 // Enables or disables the right-to-left layout for the view. If |enable| is
289 // true, the layout will become right-to-left only if the locale's language
290 // is right-to-left.
291 //
292 // By default, right-to-left UI layout is enabled for the view and therefore
293 // this function must be called (with false as the |enable| parameter) in
294 // order to disable the right-to-left layout property for a specific instance
295 // of the view. Disabling the right-to-left UI layout is necessary in case a
296 // UI element will not appear correctly when mirrored.
297 void EnableUIMirroringForRTLLanguages(bool enable) {
298 ui_mirroring_is_enabled_for_rtl_languages_ = enable;
299 }
300
301 // This method determines whether the ChromeCanvas object passed to
302 // View::Paint() needs to be transformed such that anything drawn on the
303 // canvas object during View::Paint() is flipped horizontally.
304 //
305 // By default, this function returns false (which is the initial value of
306 // |flip_canvas_on_paint_for_rtl_ui_|). View subclasses that need to paint on
307 // a flipped ChromeCanvas when the UI layout is right-to-left need to call
308 // EnableCanvasFlippingForRTLUI().
309 bool FlipCanvasOnPaintForRTLUI() const {
310 return flip_canvas_on_paint_for_rtl_ui_ ? UILayoutIsRightToLeft() : false;
311 }
312
313 // Enables or disables flipping of the ChromeCanvas during View::Paint().
314 // Note that if canvas flipping is enabled, the canvas will be flipped only
315 // if the UI layout is right-to-left; that is, the canvas will be flipped
316 // only if UILayoutIsRightToLeft() returns true.
317 //
318 // Enabling canvas flipping is useful for leaf views that draw a bitmap that
319 // needs to be flipped horizontally when the UI layout is right-to-left
[email protected]c2dacc92008-10-16 23:51:38320 // (views::Button, for example). This method is helpful for such classes
321 // because their drawing logic stays the same and they can become agnostic to
322 // the UI directionality.
initial.commit09911bf2008-07-26 23:55:29323 void EnableCanvasFlippingForRTLUI(bool enable) {
324 flip_canvas_on_paint_for_rtl_ui_ = enable;
325 }
326
327 // Returns the mirrored X position for the view, relative to the parent. If
328 // the parent view is not mirrored, this function returns bound_.left.
329 //
330 // UI mirroring is transparent to most View subclasses and therefore there is
331 // no need to call this routine from anywhere within your subclass
332 // implementation.
[email protected]63329982008-10-10 21:56:57333 int MirroredX() const;
initial.commit09911bf2008-07-26 23:55:29334
335 // Given a rectangle specified in this View's coordinate system, the function
336 // computes the 'left' value for the mirrored rectangle within this View. If
337 // the View's UI layout is not right-to-left, then bounds.x() is returned.
338 //
339 // UI mirroring is transparent to most View subclasses and therefore there is
340 // no need to call this routine from anywhere within your subclass
341 // implementation.
342 int MirroredLeftPointForRect(const gfx::Rect& rect) const;
343
344 // Given the X coordinate of a point inside the View, this function returns
345 // the mirrored X coordinate of the point if the View's UI layout is
346 // right-to-left. If the layout is left-to-right, the same X coordinate is
347 // returned.
348 //
349 // Following are a few examples of the values returned by this function for
350 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout:
351 //
352 // MirroredXCoordinateInsideView(0) -> 100
353 // MirroredXCoordinateInsideView(20) -> 80
354 // MirroredXCoordinateInsideView(99) -> 1
355 int MirroredXCoordinateInsideView(int x) const {
[email protected]6f3bb6c2008-09-17 22:25:33356 return UILayoutIsRightToLeft() ? width() - x : x;
initial.commit09911bf2008-07-26 23:55:29357 }
358
359 // 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.
381 virtual void Paint(ChromeCanvas* canvas);
382
383 // Paint the background if any. This method is called by Paint() and
384 // should rarely be invoked directly.
385 virtual void PaintBackground(ChromeCanvas* canvas);
386
387 // Paint the border if any. This method is called by Paint() and
388 // should rarely be invoked directly.
389 virtual void PaintBorder(ChromeCanvas* canvas);
390
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.
395 virtual void PaintFocusBorder(ChromeCanvas* canvas);
396
397 // Paint this View immediately.
398 virtual void PaintNow();
399
400 // Paint a view without attaching it to this view hierarchy.
401 // Any view can be painted that way.
402 // This method set bounds, calls layout and handles clipping properly. The
403 // provided view can be attached to a parent. The parent will be saved and
404 // restored. (x, y, width, height) define the floating view bounds
405 void PaintFloatingView(ChromeCanvas* canvas, View* view,
406 int x, int y, int w, int h);
407
408 // Tree functions
409
410 // Add a child View.
411 void AddChildView(View* v);
412
413 // Adds a child View at the specified position.
414 void AddChildView(int index, View* v);
415
416 // Get the child View at the specified index.
417 View* GetChildViewAt(int index) const;
418
419 // Remove a child view from this view. v's parent will change to NULL
420 void RemoveChildView(View *v);
421
422 // Remove all child view from this view. If |delete_views| is true, the views
423 // are deleted, unless marked as not parent owned.
424 void RemoveAllChildViews(bool delete_views);
425
426 // Get the number of child Views.
427 int GetChildViewCount() const;
428
429 // Get the child View at the specified point.
[email protected]613b8062008-10-14 23:45:09430 virtual View* GetViewForPoint(const gfx::Point& point);
initial.commit09911bf2008-07-26 23:55:29431
[email protected]a0dde122008-11-21 20:51:20432 // Get the Widget that hosts this View, if any.
433 virtual Widget* GetWidget() const;
initial.commit09911bf2008-07-26 23:55:29434
435 // Get the containing RootView
436 virtual RootView* GetRootView();
437
438 // Get the parent View
439 View* GetParent() const { return parent_; }
440
441 // Returns the index of the specified |view| in this view's children, or -1
442 // if the specified view is not a child of this view.
443 int GetChildIndex(View* v) const;
444
445 // Returns true if the specified view is a direct or indirect child of this
446 // view.
447 bool IsParentOf(View* v) const;
448
449 // Recursively descends the view tree starting at this view, and returns
450 // the first child that it encounters that has the given ID.
451 // Returns NULL if no matching child view is found.
452 virtual View* GetViewByID(int id) const;
453
454 // Sets and gets the ID for this view. ID should be unique within the subtree
455 // that you intend to search for it. 0 is the default ID for views.
456 void SetID(int id);
457 int GetID() const;
458
459 // A group id is used to tag views which are part of the same logical group.
460 // Focus can be moved between views with the same group using the arrow keys.
461 // Groups are currently used to implement radio button mutual exclusion.
462 void SetGroup(int gid);
463 int GetGroup() const;
464
465 // If this returns true, the views from the same group can each be focused
466 // when moving focus with the Tab/Shift-Tab key. If this returns false,
467 // only the selected view from the group (obtained with
468 // GetSelectedViewForGroup()) is focused.
469 virtual bool IsGroupFocusTraversable() const { return true; }
470
471 // Fills the provided vector with all the available views which belong to the
472 // provided group.
473 void GetViewsWithGroup(int group_id, std::vector<View*>* out);
474
475 // Return the View that is currently selected in the specified group.
476 // The default implementation simply returns the first View found for that
477 // group.
478 virtual View* GetSelectedViewForGroup(int group_id);
479
480 // Focus support
481 //
482 // Returns the view that should be selected next when pressing Tab.
483 View* GetNextFocusableView();
484
485 // Returns the view that should be selected next when pressing Shift-Tab.
486 View* GetPreviousFocusableView();
487
488 // Sets the component that should be selected next when pressing Tab, and
489 // makes the current view the precedent view of the specified one.
490 // Note that by default views are linked in the order they have been added to
491 // their container. Use this method if you want to modify the order.
492 // IMPORTANT NOTE: loops in the focus hierarchy are not supported.
493 void SetNextFocusableView(View* view);
494
495 // Return whether this view can accept the focus.
496 virtual bool IsFocusable() const;
497
498 // Sets whether this view can accept the focus.
499 // Note that this is false by default so that a view used as a container does
500 // not get the focus.
501 virtual void SetFocusable(bool focusable);
502
503 // Convenience method to retrieve the FocusManager associated with the
[email protected]a0dde122008-11-21 20:51:20504 // Widget that contains this view. This can return NULL if this view is not
505 // part of a view hierarchy with a Widget.
initial.commit09911bf2008-07-26 23:55:29506 virtual FocusManager* GetFocusManager();
507
508 // Sets a keyboard accelerator for that view. When the user presses the
509 // accelerator key combination, the AcceleratorPressed method is invoked.
510 // Note that you can set multiple accelerators for a view by invoking this
511 // method several times.
512 virtual void AddAccelerator(const Accelerator& accelerator);
513
[email protected]e8e0f362008-11-08 01:13:25514 // Removes the specified accelerator for this view.
515 virtual void RemoveAccelerator(const Accelerator& accelerator);
516
initial.commit09911bf2008-07-26 23:55:29517 // Removes all the keyboard accelerators for this view.
518 virtual void ResetAccelerators();
519
520 // Called when a keyboard accelerator is pressed.
521 // Derived classes should implement desired behavior and return true if they
522 // handled the accelerator.
523 virtual bool AcceleratorPressed(const Accelerator& accelerator) {
524 return false;
525 }
526
527 // Called on a view (if it is has focus) before an Accelerator is processed.
528 // Views that want to override an accelerator should override this method to
529 // perform the required action and return true, to indicate that the
530 // accelerator should not be processed any further.
531 virtual bool OverrideAccelerator(const Accelerator& accelerator) {
532 return false;
533 }
534
535 // Returns whether this view currently has the focus.
536 virtual bool HasFocus();
537
538 // Accessibility support
539 // TODO(klink): Move all this out to a AccessibleInfo wrapper class.
540 //
541 // Returns the MSAA default action of the current view. The string returned
542 // describes the default action that will occur when executing
543 // IAccessible::DoDefaultAction. For instance, default action of a button is
544 // 'Press'. Sets the input string appropriately, and returns true if
545 // successful.
546 virtual bool GetAccessibleDefaultAction(std::wstring* action) {
547 return false;
548 }
549
550 // Returns a string containing the mnemonic, or the keyboard shortcut, for a
551 // given control. Sets the input string appropriately, and returns true if
552 // successful.
553 virtual bool GetAccessibleKeyboardShortcut(std::wstring* shortcut) {
554 return false;
555 }
556
557 // Returns a brief, identifying string, containing a unique, readable name of
558 // a given control. Sets the input string appropriately, and returns true if
559 // successful.
560 virtual bool GetAccessibleName(std::wstring* name) { return false; }
561
[email protected]8c117712009-01-13 12:26:46562#if defined(OS_WIN)
563 // TODO(port): Make these functions using VARIANT portable.
564
initial.commit09911bf2008-07-26 23:55:29565 // Returns the MSAA role of the current view. The role is what assistive
566 // technologies (ATs) use to determine what behavior to expect from a given
567 // control. Sets the input VARIANT appropriately, and returns true if
568 // successful.
569 virtual bool GetAccessibleRole(VARIANT* role) { return false; }
570
571 // Returns the MSAA state of the current view. Sets the input VARIANT
572 // appropriately, and returns true if a change was performed successfully.
573 virtual bool GetAccessibleState(VARIANT* state) { return false; }
[email protected]8c117712009-01-13 12:26:46574#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29575
576 // Assigns a keyboard shortcut string description to the given control. Needed
577 // as a View does not know which shortcut will be associated with it until it
578 // is created to be a certain type.
579 virtual void SetAccessibleKeyboardShortcut(const std::wstring& shortcut) {}
580
581 // Assigns a string name to the given control. Needed as a View does not know
582 // which name will be associated with it until it is created to be a
583 // certain type.
584 virtual void SetAccessibleName(const std::wstring& name) {}
585
586 // Returns an instance of a wrapper class implementing the (platform-specific)
587 // accessibility interface for a given View. If one exists, it will be
588 // re-used, otherwise a new instance will be created.
589 AccessibleWrapper* GetAccessibleWrapper();
590
591 // Accessor used to determine if a child view (leaf) has accessibility focus.
592 // Returns NULL if there are no children, or if none of the children has
593 // accessibility focus.
[email protected]c2dacc92008-10-16 23:51:38594 virtual View* GetAccFocusedChildView() { return NULL; }
initial.commit09911bf2008-07-26 23:55:29595
596 // Floating views
597 //
598 // A floating view is a view that is used to paint a cell within a parent view
599 // Floating Views are painted using PaintFloatingView() above.
600 //
601 // Floating views can also be lazily created and attached to the view
602 // hierarchy to process events. To make this possible, each view is given an
603 // opportunity to create and attach a floating view right before an mouse
604 // event is processed.
605
606 // Retrieves the id for the floating view at the specified coordinates if any.
607 // Derived classes that use floating views should implement this method and
608 // return true if a view has been found and its id set in |id|.
609 virtual bool GetFloatingViewIDForPoint(int x, int y, int* id);
610
611 // Retrieves the ID of the floating view at the specified |position| and sets
612 // it in |id|.
613 // For positions NEXT and PREVIOUS, the specified |starting_id| is used as
614 // the origin, it is ignored for FIRST and LAST.
615 // Returns true if an ID was found, false otherwise.
616 // For CURRENT, the |starting_id| should be set in |id| and true returned if
617 // the |starting_id| is a valid floating view id.
618 // Derived classes that use floating views should implement this method and
619 // return a unique ID for each floating view.
620 // The default implementation always returns false.
621 virtual bool EnumerateFloatingViews(FloatingViewPosition position,
622 int starting_id,
623 int* id);
624
625 // Creates and attaches the floating view with the specified |id| to this view
626 // hierarchy and returns it.
627 // Derived classes that use floating views should implement this method.
628 //
629 // NOTE: subclasses implementing this should return NULL if passed an invalid
630 // id. An invalid ID may be passed in by the focus manager when attempting
631 // to restore focus.
632 virtual View* ValidateFloatingViewForID(int id);
633
634 // Whether the focus should automatically be restored to the last focused
635 // view. Default implementation returns true.
636 // Derived classes that want to restore focus themselves should override this
637 // method and return false.
638 virtual bool ShouldRestoreFloatingViewFocus();
639
640 // Attach a floating view to the receiving view. The view is inserted
641 // in the child view list and will behave like a normal view. |id| is the
642 // floating view id for that view.
643 void AttachFloatingView(View* v, int id);
644
645 // Return whether a view already has a floating view which bounds intersects
646 // the provided point.
647 //
648 // If the View uses right-to-left UI layout, then the given point is checked
649 // against the mirrored position of each floating View.
650 bool HasFloatingViewForPoint(int x, int y);
651
652 // Detach and delete all floating views. Call this method when your model
653 // or layout changes.
654 void DetachAllFloatingViews();
655
656 // Returns the view with the specified |id|, by calling
657 // ValidateFloatingViewForID if that view has not yet been attached.
658 virtual View* RetrieveFloatingViewForID(int id);
659
660 // Restores the focus to the previously selected floating view.
661 virtual void RestoreFloatingViewFocus();
662
663 // Goes up the parent hierarchy of this view and returns the first floating
664 // view found. Returns NULL if none were found.
665 View* RetrieveFloatingViewParent();
666
667 // Utility functions
668
669 // Note that the utility coordinate conversions functions always operate on
670 // the mirrored position of the child Views if the parent View uses a
671 // right-to-left UI layout.
672
673 // Convert a point from source coordinate system to dst coordinate system.
674 //
675 // source is a parent or a child of dst, directly or transitively.
676 // If source and dst are not in the same View hierarchy, the result is
677 // undefined.
678 // Source can be NULL in which case it means the screen coordinate system
[email protected]bb515ed2009-01-15 00:53:43679 static void ConvertPointToView(const View* src,
680 const View* dst,
initial.commit09911bf2008-07-26 23:55:29681 gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29682
683 // Convert a point from the coordinate system of a View to that of the
[email protected]a0dde122008-11-21 20:51:20684 // Widget. This is useful for example when sizing HWND children of the
685 // Widget that don't know about the View hierarchy and need to be placed
686 // relative to the Widget that is their parent.
687 static void ConvertPointToWidget(View* src, gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29688
[email protected]a0dde122008-11-21 20:51:20689 // Convert a point from a view Widget to a View dest
690 static void ConvertPointFromWidget(View *dest, gfx::Point* p);
initial.commit09911bf2008-07-26 23:55:29691
692 // Convert a point from the coordinate system of a View to that of the
693 // screen. This is useful for example when placing popup windows.
[email protected]96b667d2008-10-14 20:58:44694 static void ConvertPointToScreen(View* src, gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29695
696 // Event Handlers
697
698 // This method is invoked when the user clicks on this view.
699 // The provided event is in the receiver's coordinate system.
700 //
701 // Return true if you processed the event and want to receive subsequent
702 // MouseDraggged and MouseReleased events. This also stops the event from
703 // bubbling. If you return false, the event will bubble through parent
704 // views.
705 //
706 // If you remove yourself from the tree while processing this, event bubbling
707 // stops as if you returned true, but you will not receive future events.
708 // The return value is ignored in this case.
709 //
710 // Default implementation returns true if a ContextMenuController has been
711 // set, false otherwise. Override as needed.
712 //
713 virtual bool OnMousePressed(const MouseEvent& event);
714
715 // This method is invoked when the user clicked on this control.
716 // and is still moving the mouse with a button pressed.
717 // The provided event is in the receiver's coordinate system.
718 //
719 // Return true if you processed the event and want to receive
720 // subsequent MouseDragged and MouseReleased events.
721 //
722 // Default implementation returns true if a ContextMenuController has been
723 // set, false otherwise. Override as needed.
724 //
725 virtual bool OnMouseDragged(const MouseEvent& event);
726
727 // This method is invoked when the user releases the mouse
728 // button. The event is in the receiver's coordinate system.
729 //
730 // If canceled is true it indicates the mouse press/drag was canceled by a
731 // system/user gesture.
732 //
733 // Default implementation notifies the ContextMenuController is appropriate.
734 // Subclasses that wish to honor the ContextMenuController should invoke
735 // super.
736 virtual void OnMouseReleased(const MouseEvent& event, bool canceled);
737
738 // This method is invoked when the mouse is above this control
739 // The event is in the receiver's coordinate system.
740 //
741 // Default implementation does nothing. Override as needed.
742 virtual void OnMouseMoved(const MouseEvent& e);
743
744 // This method is invoked when the mouse enters this control.
745 //
746 // Default implementation does nothing. Override as needed.
747 virtual void OnMouseEntered(const MouseEvent& event);
748
749 // This method is invoked when the mouse exits this control
750 // The provided event location is always (0, 0)
751 // Default implementation does nothing. Override as needed.
752 virtual void OnMouseExited(const MouseEvent& event);
753
754 // Set the MouseHandler for a drag session.
755 //
756 // A drag session is a stream of mouse events starting
757 // with a MousePressed event, followed by several MouseDragged
758 // events and finishing with a MouseReleased event.
759 //
760 // This method should be only invoked while processing a
761 // MouseDragged or MouseReleased event.
762 //
763 // All further mouse dragged and mouse up events will be sent
764 // the MouseHandler, even if it is reparented to another window.
765 //
766 // The MouseHandler is automatically cleared when the control
767 // comes back from processing the MouseReleased event.
768 //
769 // Note: if the mouse handler is no longer connected to a
770 // view hierarchy, events won't be sent.
771 //
772 virtual void SetMouseHandler(View* new_mouse_handler);
773
774 // Request the keyboard focus. The receiving view will become the
775 // focused view.
776 virtual void RequestFocus();
777
778 // Invoked when a view is about to gain focus
779 virtual void WillGainFocus();
780
781 // Invoked when a view just gained focus.
782 virtual void DidGainFocus();
783
784 // Invoked when a view is about lose focus
785 virtual void WillLoseFocus();
786
787 // Invoked when a view is about to be requested for focus due to the focus
788 // traversal. Reverse is this request was generated going backward
789 // (Shift-Tab).
790 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) { }
791
792 // Invoked when a key is pressed or released.
793 // Subclasser should return true if the event has been processed and false
794 // otherwise. If the event has not been processed, the parent will be given a
795 // chance.
796 virtual bool OnKeyPressed(const KeyEvent& e);
797 virtual bool OnKeyReleased(const KeyEvent& e);
798
799 // Whether the view wants to receive Tab and Shift-Tab key events.
800 // If false, Tab and Shift-Tabs key events are used for focus traversal and
801 // are not sent to the view. If true, the events are sent to the view and not
802 // used for focus traversal.
803 // This implementation returns false (so that by default views handle nicely
804 // the keyboard focus traversal).
805 virtual bool CanProcessTabKeyEvents();
806
807 // Invoked when the user uses the mousewheel. Implementors should return true
808 // if the event has been processed and false otherwise. This message is sent
809 // if the view is focused. If the event has not been processed, the parent
810 // will be given a chance.
811 virtual bool OnMouseWheel(const MouseWheelEvent& e);
812
813 // Drag and drop functions.
814
815 // Set/get the DragController. See description of DragController for more
816 // information.
817 void SetDragController(DragController* drag_controller);
818 DragController* GetDragController();
819
820 // During a drag and drop session when the mouse moves the view under the
821 // mouse is queried to see if it should be a target for the drag and drop
822 // session. A view indicates it is a valid target by returning true from
823 // CanDrop. If a view returns true from CanDrop,
824 // OnDragEntered is sent to the view when the mouse first enters the view,
825 // as the mouse moves around within the view OnDragUpdated is invoked.
826 // If the user releases the mouse over the view and OnDragUpdated returns a
827 // valid drop, then OnPerformDrop is invoked. If the mouse moves outside the
828 // view or over another view that wants the drag, OnDragExited is invoked.
829 //
830 // Similar to mouse events, the deepest view under the mouse is first checked
831 // if it supports the drop (Drop). If the deepest view under
832 // the mouse does not support the drop, the ancestors are walked until one
833 // is found that supports the drop.
834
835 // A view that supports drag and drop must override this and return true if
836 // data contains a type that may be dropped on this view.
837 virtual bool CanDrop(const OSExchangeData& data);
838
839 // OnDragEntered is invoked when the mouse enters this view during a drag and
840 // drop session and CanDrop returns true. This is immediately
841 // followed by an invocation of OnDragUpdated, and eventually one of
842 // OnDragExited or OnPerformDrop.
843 virtual void OnDragEntered(const DropTargetEvent& event);
844
845 // Invoked during a drag and drop session while the mouse is over the view.
846 // This should return a bitmask of the DragDropTypes::DragOperation supported
847 // based on the location of the event. Return 0 to indicate the drop should
848 // not be accepted.
849 virtual int OnDragUpdated(const DropTargetEvent& event);
850
851 // Invoked during a drag and drop session when the mouse exits the views, or
852 // when the drag session was canceled and the mouse was over the view.
853 virtual void OnDragExited();
854
855 // Invoked during a drag and drop session when OnDragUpdated returns a valid
856 // operation and the user release the mouse.
857 virtual int OnPerformDrop(const DropTargetEvent& event);
858
859 // Returns true if the mouse was dragged enough to start a drag operation.
860 // delta_x and y are the distance the mouse was dragged.
861 static bool ExceededDragThreshold(int delta_x, int delta_y);
862
863 // This method is the main entry point to process paint for this
864 // view and its children. This method is called by the painting
865 // system. You should call this only if you want to draw a sub tree
866 // inside a custom graphics.
867 // To customize painting override either the Paint or PaintChildren method,
868 // not this one.
869 virtual void ProcessPaint(ChromeCanvas* canvas);
870
871 // Paint the View's child Views, in reverse order.
872 virtual void PaintChildren(ChromeCanvas* canvas);
873
874 // Sets the ContextMenuController. Setting this to non-null makes the View
875 // process mouse events.
876 void SetContextMenuController(ContextMenuController* menu_controller);
877 ContextMenuController* GetContextMenuController() {
878 return context_menu_controller_;
879 }
880
[email protected]042811c2008-10-31 21:31:34881 // Provides default implementation for context menu handling. The default
882 // implementation calls the ShowContextMenu of the current
883 // ContextMenuController (if it is not NULL). Overridden in subclassed views
884 // to provide right-click menu display triggerd by the keyboard (i.e. for the
885 // Chrome toolbar Back and Forward buttons). No source needs to be specified,
886 // as it is always equal to the current View.
887 virtual void ShowContextMenu(int x,
888 int y,
889 bool is_mouse_gesture);
890
[email protected]9a3f0ac22008-11-14 03:24:02891 // The background object is owned by this object and may be NULL.
892 void set_background(Background* b) { background_.reset(b); }
893 const Background* background() const { return background_.get(); }
initial.commit09911bf2008-07-26 23:55:29894
[email protected]9a3f0ac22008-11-14 03:24:02895 // The border object is owned by this object and may be NULL.
896 void set_border(Border* b) { border_.reset(b); }
897 const Border* border() const { return border_.get(); }
initial.commit09911bf2008-07-26 23:55:29898
899 // Returns the insets of the current border. If there is no border an empty
900 // insets is returned.
901 gfx::Insets GetInsets() const;
902
[email protected]8c117712009-01-13 12:26:46903#if defined(OS_WIN)
904 // TODO(port): Make GetCursorForPoint portable.
905
initial.commit09911bf2008-07-26 23:55:29906 // Return the cursor that should be used for this view or NULL if
907 // the default cursor should be used. The provided point is in the
908 // receiver's coordinate system.
909 virtual HCURSOR GetCursorForPoint(Event::EventType event_type, int x, int y);
[email protected]8c117712009-01-13 12:26:46910#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29911
912 // Convenience to test whether a point is within this view's bounds
[email protected]613b8062008-10-14 23:45:09913 virtual bool HitTest(const gfx::Point& l) const;
initial.commit09911bf2008-07-26 23:55:29914
915 // Gets the tooltip for this View. If the View does not have a tooltip,
916 // return false. If the View does have a tooltip, copy the tooltip into
917 // the supplied string and return true.
918 // Any time the tooltip text that a View is displaying changes, it must
919 // invoke TooltipTextChanged.
920 // The x/y provide the coordinates of the mouse (relative to this view).
921 virtual bool GetTooltipText(int x, int y, std::wstring* tooltip);
922
923 // Returns the location (relative to this View) for the text on the tooltip
924 // to display. If false is returned (the default), the tooltip is placed at
925 // a default position.
[email protected]0a1d36b22008-10-17 19:33:09926 virtual bool GetTooltipTextOrigin(int x, int y, gfx::Point* loc);
initial.commit09911bf2008-07-26 23:55:29927
928 // Set whether this view is owned by its parent. A view that is owned by its
929 // parent is automatically deleted when the parent is deleted. The default is
930 // true. Set to false if the view is owned by another object and should not
931 // be deleted by its parent.
932 void SetParentOwned(bool f);
933
934 // Return whether a view is owned by its parent. See SetParentOwned()
935 bool IsParentOwned() const;
936
937 // Return the receiving view's class name. A view class is a string which
938 // uniquely identifies the view class. It is intended to be used as a way to
939 // find out during run time if a view can be safely casted to a specific view
940 // subclass. The default implementation returns kViewClassName.
941 virtual std::string GetClassName() const;
942
943 // Returns the visible bounds of the receiver in the receivers coordinate
944 // system.
945 //
946 // When traversing the View hierarchy in order to compute the bounds, the
947 // function takes into account the mirroring setting for each View and
948 // therefore it will return the mirrored version of the visible bounds if
949 // need be.
950 gfx::Rect GetVisibleBounds();
951
952 // Subclasses that contain traversable children that are not directly
953 // accessible through the children hierarchy should return the associated
954 // FocusTraversable for the focus traversal to work properly.
955 virtual FocusTraversable* GetFocusTraversable() { return NULL; }
956
957#ifndef NDEBUG
958 // Debug method that logs the view hierarchy to the output.
959 void PrintViewHierarchy();
960
961 // Debug method that logs the focus traversal hierarchy to the output.
962 void PrintFocusHierarchy();
963#endif
964
965 // The following methods are used by ScrollView to determine the amount
966 // to scroll relative to the visible bounds of the view. For example, a
967 // return value of 10 indicates the scrollview should scroll 10 pixels in
968 // the appropriate direction.
969 //
970 // Each method takes the following parameters:
971 //
972 // is_horizontal: if true, scrolling is along the horizontal axis, otherwise
973 // the vertical axis.
974 // is_positive: if true, scrolling is by a positive amount. Along the
975 // vertical axis scrolling by a positive amount equates to
976 // scrolling down.
977 //
978 // The return value should always be positive and gives the number of pixels
979 // to scroll. ScrollView interprets a return value of 0 (or negative)
980 // to scroll by a default amount.
981 //
982 // See VariableRowHeightScrollHelper and FixedRowHeightScrollHelper for
983 // implementations of common cases.
984 virtual int GetPageScrollIncrement(ScrollView* scroll_view,
985 bool is_horizontal, bool is_positive);
986 virtual int GetLineScrollIncrement(ScrollView* scroll_view,
987 bool is_horizontal, bool is_positive);
988
989 protected:
initial.commit09911bf2008-07-26 23:55:29990 // The id of this View. Used to find this View.
991 int id_;
992
993 // The group of this view. Some view subclasses use this id to find other
994 // views of the same group. For example radio button uses this information
995 // to find other radio buttons.
996 int group_;
997
998#ifndef NDEBUG
999 // Returns true if the View is currently processing a paint.
1000 virtual bool IsProcessingPaint() const;
1001#endif
1002
[email protected]f704ee72008-11-10 21:31:591003 // Returns the location, in screen coordinates, to show the context menu at
1004 // when the context menu is shown from the keyboard. This implementation
1005 // returns the middle of the visible region of this view.
1006 //
1007 // This method is invoked when the context menu is shown by way of the
1008 // keyboard.
1009 virtual gfx::Point GetKeyboardContextMenuLocation();
1010
[email protected]82739cf2008-09-16 00:37:561011 // Called by HitTest to see if this View has a custom hit test mask. If the
1012 // return value is true, GetHitTestMask will be called to obtain the mask.
1013 // Default value is false, in which case the View will hit-test against its
1014 // bounds.
1015 virtual bool HasHitTestMask() const;
1016
1017 // Called by HitTest to retrieve a mask for hit-testing against. Subclasses
1018 // override to provide custom shaped hit test regions.
1019 virtual void GetHitTestMask(gfx::Path* mask) const;
1020
initial.commit09911bf2008-07-26 23:55:291021 // This method is invoked when the tree changes.
1022 //
1023 // When a view is removed, it is invoked for all children and grand
1024 // children. For each of these views, a notification is sent to the
1025 // view and all parents.
1026 //
1027 // When a view is added, a notification is sent to the view, all its
1028 // parents, and all its children (and grand children)
1029 //
1030 // Default implementation does nothing. Override to perform operations
1031 // required when a view is added or removed from a view hierarchy
1032 //
1033 // parent is the new or old parent. Child is the view being added or
1034 // removed.
1035 //
1036 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
1037
1038 // When SetVisible() changes the visibility of a view, this method is
1039 // invoked for that view as well as all the children recursively.
1040 virtual void VisibilityChanged(View* starting_from, bool is_visible);
1041
1042 // Views must invoke this when the tooltip text they are to display changes.
1043 void TooltipTextChanged();
1044
1045 // Actual implementation of GetViewForPoint.
[email protected]613b8062008-10-14 23:45:091046 virtual View* GetViewForPoint(const gfx::Point& point,
1047 bool can_create_floating);
initial.commit09911bf2008-07-26 23:55:291048
1049 // Sets whether this view wants notification when its visible bounds relative
1050 // to the root view changes. If true, this view is notified any time the
1051 // origin of one its ancestors changes, or the portion of the bounds not
1052 // obscured by ancestors changes. The default is false.
1053 void SetNotifyWhenVisibleBoundsInRootChanges(bool value);
1054 bool GetNotifyWhenVisibleBoundsInRootChanges();
1055
1056 // Notification that this views visible bounds, relative to the RootView
1057 // has changed. The visible bounds corresponds to the region of the
1058 // view not obscured by other ancestors.
1059 virtual void VisibleBoundsInRootChanged() {}
1060
1061 // Sets the keyboard focus to this View. The correct way to set the focus is
1062 // to call RequestFocus() on the view. This method is called when the focus is
1063 // set and gives an opportunity to subclasses to perform any extra focus steps
1064 // (for example native component set the native focus on their native
1065 // component). The default behavior is to set the native focus on the root
[email protected]a0dde122008-11-21 20:51:201066 // Widget, which is what is appropriate for views that have no native window
1067 // associated with them (so the root view gets the keyboard messages).
initial.commit09911bf2008-07-26 23:55:291068 virtual void Focus();
1069
initial.commit09911bf2008-07-26 23:55:291070 // Invoked when a key is pressed before the key event is processed by the
1071 // focus manager for accelerators. This gives a chance to the view to
1072 // override an accelerator. Subclasser should return false if they want to
1073 // process the key event and not have it translated to an accelerator (if
1074 // any). In that case, OnKeyPressed will subsequently be invoked for that
1075 // event.
1076 virtual bool ShouldLookupAccelerators(const KeyEvent& e) { return true; }
1077
1078 // A convenience method for derived classes which have floating views with IDs
1079 // that are consecutive numbers in an interval [|low_bound|, |high_bound|[.
1080 // They can call this method in their EnumerateFloatingViews implementation.
1081 // If |ascending_order| is true, the first id is |low_bound|, the next after
1082 // id n is n + 1, and so on. If |ascending_order| is false, the order is
1083 // reversed, first id is |high_bound|, the next id after id n is n -1...
1084 static bool EnumerateFloatingViewsForInterval(int low_bound, int high_bound,
1085 bool ascending_order,
1086 FloatingViewPosition position,
1087 int starting_id,
1088 int* id);
1089
1090 // These are cover methods that invoke the method of the same name on
1091 // the DragController. Subclasses may wish to override rather than install
1092 // a DragController.
1093 // See DragController for a description of these methods.
1094 virtual int GetDragOperations(int press_x, int press_y);
1095 virtual void WriteDragData(int press_x, int press_y, OSExchangeData* data);
1096
1097 // Invoked from DoDrag after the drag completes. This implementation does
1098 // nothing, and is intended for subclasses to do cleanup.
1099 virtual void OnDragDone();
1100
1101 // Returns whether we're in the middle of a drag session that was initiated
1102 // by us.
1103 bool InDrag();
1104
1105 // Whether this view is enabled.
1106 bool enabled_;
1107
1108 // Whether the view can be focused.
1109 bool focusable_;
1110
1111 private:
1112 friend class RootView;
1113 friend class FocusManager;
1114 friend class ViewStorage;
1115
1116 // Used to track a drag. RootView passes this into
1117 // ProcessMousePressed/Dragged.
1118 struct DragInfo {
1119 // Sets possible_drag to false and start_x/y to 0. This is invoked by
1120 // RootView prior to invoke ProcessMousePressed.
1121 void Reset();
1122
1123 // Sets possible_drag to true and start_x/y to the specified coordinates.
1124 // This is invoked by the target view if it detects the press may generate
1125 // a drag.
1126 void PossibleDrag(int x, int y);
1127
1128 // Whether the press may generate a drag.
1129 bool possible_drag;
1130
1131 // Coordinates of the mouse press.
1132 int start_x;
1133 int start_y;
1134 };
1135
[email protected]6ff244f2009-01-20 20:38:081136 // Returns how much the mouse needs to move in one direction to start a
1137 // drag. These methods cache in a platform-appropriate way. These values are
1138 // used by the public static method ExceededDragThreshold().
1139 static int GetHorizontalDragThreshold();
1140 static int GetVerticalDragThreshold();
1141
initial.commit09911bf2008-07-26 23:55:291142 // RootView invokes these. These in turn invoke the appropriate OnMouseXXX
1143 // method. If a drag is detected, DoDrag is invoked.
1144 bool ProcessMousePressed(const MouseEvent& e, DragInfo* drop_info);
1145 bool ProcessMouseDragged(const MouseEvent& e, DragInfo* drop_info);
1146 void ProcessMouseReleased(const MouseEvent& e, bool canceled);
1147
1148 // Starts a drag and drop operation originating from this view. This invokes
1149 // WriteDragData to write the data and GetDragOperations to determine the
1150 // supported drag operations. When done, OnDragDone is invoked.
[email protected]c2dacc92008-10-16 23:51:381151 void DoDrag(const MouseEvent& e, int press_x, int press_y);
initial.commit09911bf2008-07-26 23:55:291152
1153 // Adds a child View at the specified position. |floating_view| should be true
1154 // if the |v| is a floating view.
1155 void AddChildView(int index, View* v, bool floating_view);
1156
1157 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true,
1158 // the next and previous focusable views of views pointing to this view are
1159 // updated. If |update_tool_tip| is true, the tooltip is updated. If
1160 // |delete_removed_view| is true, the view is also deleted (if it is parent
1161 // owned).
1162 void DoRemoveChildView(View* view,
1163 bool update_focus_cycle,
1164 bool update_tool_tip,
1165 bool delete_removed_view);
1166
1167 // Sets the parent View. This is called automatically by AddChild and is
1168 // thus private.
1169 void SetParent(View *parent);
1170
1171 // Call ViewHierarchyChanged for all child views on all parents
1172 void PropagateRemoveNotifications(View* parent);
1173
1174 // Call ViewHierarchyChanged for all children
1175 void PropagateAddNotifications(View* parent, View* child);
1176
1177 // Call VisibilityChanged() recursively for all children.
1178 void PropagateVisibilityNotifications(View* from, bool is_visible);
1179
1180 // Takes care of registering/unregistering accelerators if
1181 // |register_accelerators| true and calls ViewHierarchyChanged().
1182 void ViewHierarchyChangedImpl(bool register_accelerators,
[email protected]bb515ed2009-01-15 00:53:431183 bool is_add,
1184 View* parent,
1185 View* child);
initial.commit09911bf2008-07-26 23:55:291186
1187 // This is the actual implementation for ConvertPointToView()
1188 // Attempts a parent -> child conversion and then a
1189 // child -> parent conversion if try_other_direction is true
[email protected]bb515ed2009-01-15 00:53:431190 static void ConvertPointToView(const View* src,
1191 const View* dst,
initial.commit09911bf2008-07-26 23:55:291192 gfx::Point* point,
1193 bool try_other_direction);
1194
[email protected]a0dde122008-11-21 20:51:201195 // Propagates UpdateTooltip() to the TooltipManager for the Widget.
initial.commit09911bf2008-07-26 23:55:291196 // This must be invoked any time the View hierarchy changes in such a way
1197 // the view under the mouse differs. For example, if the bounds of a View is
1198 // changed, this is invoked. Similarly, as Views are added/removed, this
1199 // is invoked.
1200 void UpdateTooltip();
1201
1202 // Recursively descends through all descendant views,
1203 // registering/unregistering all views that want visible bounds in root
1204 // view notification.
1205 static void RegisterChildrenForVisibleBoundsNotification(RootView* root,
1206 View* view);
1207 static void UnregisterChildrenForVisibleBoundsNotification(RootView* root,
1208 View* view);
1209
1210 // Adds/removes view to the list of descendants that are notified any time
1211 // this views location and possibly size are changed.
1212 void AddDescendantToNotify(View* view);
1213 void RemoveDescendantToNotify(View* view);
1214
1215 // Initialize the previous/next focusable views of the specified view relative
1216 // to the view at the specified index.
1217 void InitFocusSiblings(View* view, int index);
1218
1219 // Actual implementation of PrintFocusHierarchy.
1220 void PrintViewHierarchyImp(int indent);
1221 void PrintFocusHierarchyImp(int indent);
1222
1223 // Registers/unregister this view's keyboard accelerators with the
1224 // FocusManager.
1225 void RegisterAccelerators();
1226 void UnregisterAccelerators();
1227
1228 // Returns the number of children that are actually attached floating views.
1229 int GetFloatingViewCount() const;
1230
1231 // Returns the id for this floating view.
1232 int GetFloatingViewID();
1233
1234 // Returns whether this view is a floating view.
1235 bool IsFloatingView();
1236
1237 // Sets in |path| the path in the view hierarchy from |start| to |end| (the
1238 // path is the list of indexes in each view's children to get from |start|
1239 // to |end|).
1240 // Returns true if |start| and |view| are connected and the |path| has been
1241 // retrieved succesfully, false otherwise.
1242 static bool GetViewPath(View* start, View* end, std::vector<int>* path);
1243
1244 // Returns the view at the end of the specified |path|, starting at the
1245 // |start| view.
1246 static View* GetViewForPath(View* start, const std::vector<int>& path);
1247
[email protected]80f8b9f2008-10-16 18:17:471248 // This View's bounds in the parent coordinate system.
1249 gfx::Rect bounds_;
1250
initial.commit09911bf2008-07-26 23:55:291251 // This view's parent
1252 View *parent_;
1253
1254 // This view's children.
1255 typedef std::vector<View*> ViewList;
1256 ViewList child_views_;
1257
1258 // List of floating children. A floating view is always referenced by
1259 // child_views_ and will be deleted on destruction just like any other
1260 // child view.
1261 ViewList floating_views_;
1262
1263 // Maps a floating view to its floating view id.
1264 std::map<View*, int> floating_views_ids_;
1265
1266 // Whether we want the focus to be restored. This is used to store/restore
1267 // focus for floating views.
1268 bool should_restore_focus_;
1269
1270 // The View's LayoutManager defines the sizing heuristics applied to child
1271 // Views. The default is absolute positioning according to bounds_.
1272 scoped_ptr<LayoutManager> layout_manager_;
1273
1274 // Visible state
1275 bool is_visible_;
1276
1277 // Background
[email protected]9a3f0ac22008-11-14 03:24:021278 scoped_ptr<Background> background_;
initial.commit09911bf2008-07-26 23:55:291279
1280 // Border.
[email protected]9a3f0ac22008-11-14 03:24:021281 scoped_ptr<Border> border_;
initial.commit09911bf2008-07-26 23:55:291282
1283 // Whether this view is owned by its parent.
1284 bool is_parent_owned_;
1285
1286 // See SetNotifyWhenVisibleBoundsInRootChanges.
1287 bool notify_when_visible_bounds_in_root_changes_;
1288
1289 // Whether or not RegisterViewForVisibleBoundsNotification on the RootView
1290 // has been invoked.
1291 bool registered_for_visible_bounds_notification_;
1292
1293 // List of descendants wanting notification when their visible bounds change.
1294 scoped_ptr<ViewList> descendants_to_notify_;
1295
1296 // Next view to be focused when the Tab key is pressed.
1297 View* next_focusable_view_;
1298
1299 // Next view to be focused when the Shift-Tab key combination is pressed.
1300 View* previous_focusable_view_;
1301
1302 // The list of accelerators.
[email protected]1eb89e82008-08-15 12:27:031303 scoped_ptr<std::vector<Accelerator> > accelerators_;
initial.commit09911bf2008-07-26 23:55:291304
1305 // The task used to restore automatically the focus to the last focused
1306 // floating view.
1307 RestoreFocusTask* restore_focus_view_task_;
1308
1309 // The menu controller.
1310 ContextMenuController* context_menu_controller_;
1311
[email protected]6ff244f2009-01-20 20:38:081312#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291313 // The accessibility implementation for this View.
1314 scoped_ptr<AccessibleWrapper> accessibility_;
[email protected]6ff244f2009-01-20 20:38:081315#endif
initial.commit09911bf2008-07-26 23:55:291316
1317 DragController* drag_controller_;
1318
1319 // Indicates whether or not the view is going to be mirrored (that is, use a
1320 // right-to-left UI layout) if the locale's language is a right-to-left
1321 // language like Arabic or Hebrew.
1322 bool ui_mirroring_is_enabled_for_rtl_languages_;
1323
1324 // Indicates whether or not the ChromeCanvas object passed to View::Paint()
1325 // is going to be flipped horizontally (using the appropriate transform) on
1326 // right-to-left locales for this View.
1327 bool flip_canvas_on_paint_for_rtl_ui_;
1328
[email protected]1eb89e82008-08-15 12:27:031329 DISALLOW_COPY_AND_ASSIGN(View);
initial.commit09911bf2008-07-26 23:55:291330};
1331
[email protected]c2dacc92008-10-16 23:51:381332} // namespace views
initial.commit09911bf2008-07-26 23:55:291333
[email protected]1eb89e82008-08-15 12:27:031334#endif // CHROME_VIEWS_VIEW_H_