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