blob: d56d94fd18c4c944c33a3f69425a1327e8f9fdda [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
initial.commit09911bf2008-07-26 23:55:298#include <map>
9#include <vector>
10
[email protected]1eb89e82008-08-15 12:27:0311// TODO(maruel): Remove these once WTL::CRect and WTL::CPoint are no more used.
12#include <atlbase.h>
13#include <atlapp.h>
14#include <atlmisc.h>
15
initial.commit09911bf2008-07-26 23:55:2916#include "base/gfx/rect.h"
17#include "base/scoped_ptr.h"
initial.commit09911bf2008-07-26 23:55:2918#include "chrome/views/accelerator.h"
initial.commit09911bf2008-07-26 23:55:2919
[email protected]1eb89e82008-08-15 12:27:0320namespace gfx {
21class Insets;
[email protected]82739cf2008-09-16 00:37:5622class Path;
[email protected]1eb89e82008-08-15 12:27:0323}
24
25class AccessibleWrapper;
initial.commit09911bf2008-07-26 23:55:2926class ChromeCanvas;
27class OSExchangeData;
28class SkBitmap;
29
30namespace ChromeViews {
31
32class Background;
33class Border;
34class FocusManager;
35class FocusTraversable;
36class LayoutManager;
37class RestoreFocusTask;
38class RootView;
39class ScrollView;
40class ViewContainer;
41
42// ContextMenuController is responsible for showing the context menu for a
43// View. To use a ContextMenuController invoke SetContextMenuController on a
44// View. When the appropriate user gesture occurs ShowContextMenu is invoked
45// on the ContextMenuController.
46//
47// Setting a ContextMenuController on a view makes the view process mouse
48// events.
49//
50// It is up to subclasses that do their own mouse processing to invoke
51// the appropriate ContextMenuController method, typically by invoking super's
52// implementation for mouse processing.
53//
54class ContextMenuController {
55 public:
56 // Invoked to show the context menu for the source view. If is_mouse_gesture
57 // is true, the x/y coordinate are the location of the mouse. If
58 // is_mouse_gesture is false, this method was not invoked by a mouse gesture
59 // and x/y is the recommended location to show the menu at.
60 //
61 // x/y is in screen coordinates.
62 virtual void ShowContextMenu(View* source,
63 int x,
64 int y,
65 bool is_mouse_gesture) = 0;
66};
67
68// DragController is responsible for writing drag data for a view, as well as
69// supplying the supported drag operations. Use DragController if you don't
70// want to subclass.
71
72class DragController {
73 public:
74 // Writes the data for the drag.
75 virtual void WriteDragData(View* sender,
76 int press_x,
77 int press_y,
78 OSExchangeData* data) = 0;
79
80 // Returns the supported drag operations (see DragDropTypes for possible
81 // values). A drag is only started if this returns a non-zero value.
82 virtual int GetDragOperations(View* sender, int x, int y) = 0;
83};
84
85
86/////////////////////////////////////////////////////////////////////////////
87//
88// View class
89//
90// A View is a rectangle within the ChromeViews View hierarchy. It is the
91// base class for all Views.
92//
93// A View is a container of other Views (there is no such thing as a Leaf
94// View - makes code simpler, reduces type conversion headaches, design
95// mistakes etc)
96//
97// The View contains basic properties for sizing (bounds), layout (flex,
98// orientation, etc), painting of children and event dispatch.
99//
100// The View also uses a simple Box Layout Manager similar to XUL's
101// SprocketLayout system. Alternative Layout Managers implementing the
102// LayoutManager interface can be used to lay out children if required.
103//
104// It is up to the subclass to implement Painting and storage of subclass -
105// specific properties and functionality.
106//
107/////////////////////////////////////////////////////////////////////////////
108class View : public AcceleratorTarget {
109 public:
110
111 // Used in EnumerateFloatingViews() to specify which floating view to
112 // retrieve.
113 enum FloatingViewPosition {
114 FIRST = 0,
115 NEXT,
116 PREVIOUS,
117 LAST,
118 CURRENT
119 };
120
[email protected]6f3bb6c2008-09-17 22:25:33121 // Used in the versions of GetBounds() and x() that take a transformation
initial.commit09911bf2008-07-26 23:55:29122 // parameter in order to determine whether or not to take into account the
123 // mirroring setting of the View when returning bounds positions.
124 enum PositionMirroringSettings {
125 IGNORE_MIRRORING_TRANSFORMATION = 0,
126 APPLY_MIRRORING_TRANSFORMATION
127 };
128
129 // The view class name.
130 static char kViewClassName[];
131
132 View();
133 virtual ~View();
134
135 // Sizing functions
136
137 // Get the bounds of the View, relative to the parent. Essentially, this
138 // function returns the bounds_ rectangle.
139 //
140 // This is the function subclasses should use whenever they need to obtain
141 // the bounds of one of their child views (for example, when implementing
142 // View::Layout()).
[email protected]0d8ea702008-10-14 17:03:07143 // TODO(beng): Convert |bounds_| to a gfx::Rect.
144 gfx::Rect bounds() const { return gfx::Rect(bounds_); }
initial.commit09911bf2008-07-26 23:55:29145
146 // Return the bounds of the View, relative to the parent. If
147 // |settings| is IGNORE_MIRRORING_TRANSFORMATION, the function returns the
148 // bounds_ rectangle. If |settings| is APPLY_MIRRORING_SETTINGS AND the
149 // parent View is using a right-to-left UI layout, then the function returns
150 // a shifted version of the bounds_ rectangle that represents the mirrored
151 // View bounds.
152 //
153 // NOTE: in the vast majority of the cases, the mirroring implementation is
154 // transparent to the View subclasses and therefore you should use the
155 // version of GetBounds() which does not take a transformation settings
156 // parameter.
[email protected]0d8ea702008-10-14 17:03:07157 gfx::Rect GetBounds(PositionMirroringSettings settings) const;
initial.commit09911bf2008-07-26 23:55:29158
159 // Set the bounds in the parent's coordinate system.
160 void SetBounds(const CRect& bounds);
161 void SetBounds(int x, int y, int width, int height);
[email protected]6f3bb6c2008-09-17 22:25:33162 void SetX(int x) { SetBounds(x, y(), width(), height()); }
163 void SetY(int y) { SetBounds(x(), y, width(), height()); }
initial.commit09911bf2008-07-26 23:55:29164
165 // Returns the left coordinate of the View, relative to the parent View,
[email protected]6f3bb6c2008-09-17 22:25:33166 // which is the value of bounds_.left.
initial.commit09911bf2008-07-26 23:55:29167 //
168 // This is the function subclasses should use whenever they need to obtain
169 // the left position of one of their child views (for example, when
170 // implementing View::Layout()).
[email protected]6f3bb6c2008-09-17 22:25:33171 int x() const {
172 // This is equivalent to GetX(IGNORE_MIRRORING_TRANSFORMATION), but
173 // inlinable.
174 return bounds_.left;
initial.commit09911bf2008-07-26 23:55:29175 };
176
177 // Return the left coordinate of the View, relative to the parent. If
178 // |settings| is IGNORE_MIRRORING_SETTINGS, the function returns the value of
179 // bounds_.left. If |settings| is APPLY_MIRRORING_SETTINGS AND the parent
180 // View is using a right-to-left UI layout, then the function returns the
181 // mirrored value of bounds_.left.
182 //
183 // NOTE: in the vast majority of the cases, the mirroring implementation is
184 // transparent to the View subclasses and therefore you should use the
[email protected]6f3bb6c2008-09-17 22:25:33185 // paremeterless version of x() when you need to get the X
initial.commit09911bf2008-07-26 23:55:29186 // coordinate of a child View.
187 int GetX(PositionMirroringSettings settings) const;
188
[email protected]6f3bb6c2008-09-17 22:25:33189 int y() const {
initial.commit09911bf2008-07-26 23:55:29190 return bounds_.top;
191 };
[email protected]6f3bb6c2008-09-17 22:25:33192 int width() const {
initial.commit09911bf2008-07-26 23:55:29193 return bounds_.Width();
194 };
[email protected]6f3bb6c2008-09-17 22:25:33195 int height() const {
initial.commit09911bf2008-07-26 23:55:29196 return bounds_.Height();
197 };
198
199 // Return this control local bounds. If include_border is true, local bounds
[email protected]6f3bb6c2008-09-17 22:25:33200 // is the rectangle {0, 0, width(), height()}, otherwise, it does not
initial.commit09911bf2008-07-26 23:55:29201 // include the area where the border (if any) is painted.
202 void GetLocalBounds(CRect* out, bool include_border) const;
203
204 // Get the size of the View
205 void GetSize(CSize* out) const;
206
207 // Get the position of the View, relative to the parent.
208 //
209 // Note that if the parent uses right-to-left UI layout, then the mirrored
[email protected]6f3bb6c2008-09-17 22:25:33210 // position of this View is returned. Use x()/y() if you want to ignore
initial.commit09911bf2008-07-26 23:55:29211 // mirroring.
212 void GetPosition(CPoint* out) const;
213
214 // Get the size the View would like to be, if enough space were available.
215 virtual void GetPreferredSize(CSize* out);
216
217 // Convenience method that sizes this view to its preferred size.
218 void SizeToPreferredSize();
219
220 // Gets the minimum size of the view. View's implementation invokes
221 // GetPreferredSize.
222 virtual void GetMinimumSize(CSize* out);
223
224 // Return the height necessary to display this view with the provided width.
225 // View's implementation returns the value from getPreferredSize.cy.
226 // Override if your View's preferred height depends upon the width (such
227 // as with Labels).
228 virtual int GetHeightForWidth(int w);
229
230 // This method is invoked when this object size or position changes.
231 // The default implementation does nothing.
232 virtual void DidChangeBounds(const CRect& previous, const CRect& current);
233
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
320 // (ChromeViews::Button, for example). This method is helpful for such
321 // classes because their drawing logic stays the same and they can become
322 // agnostic to the UI directionality.
323 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.
364 virtual void SchedulePaint(const CRect& r, bool urgent);
365
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
432 // Get the containing ViewContainer
433 virtual ViewContainer* GetViewContainer() const;
434
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
504 // container window that contains this view. This can return NULL if this
505 // view is not part of a view hierarchy with a ViewContainer.
506 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
514 // Removes all the keyboard accelerators for this view.
515 virtual void ResetAccelerators();
516
517 // Called when a keyboard accelerator is pressed.
518 // Derived classes should implement desired behavior and return true if they
519 // handled the accelerator.
520 virtual bool AcceleratorPressed(const Accelerator& accelerator) {
521 return false;
522 }
523
524 // Called on a view (if it is has focus) before an Accelerator is processed.
525 // Views that want to override an accelerator should override this method to
526 // perform the required action and return true, to indicate that the
527 // accelerator should not be processed any further.
528 virtual bool OverrideAccelerator(const Accelerator& accelerator) {
529 return false;
530 }
531
532 // Returns whether this view currently has the focus.
533 virtual bool HasFocus();
534
535 // Accessibility support
536 // TODO(klink): Move all this out to a AccessibleInfo wrapper class.
537 //
538 // Returns the MSAA default action of the current view. The string returned
539 // describes the default action that will occur when executing
540 // IAccessible::DoDefaultAction. For instance, default action of a button is
541 // 'Press'. Sets the input string appropriately, and returns true if
542 // successful.
543 virtual bool GetAccessibleDefaultAction(std::wstring* action) {
544 return false;
545 }
546
547 // Returns a string containing the mnemonic, or the keyboard shortcut, for a
548 // given control. Sets the input string appropriately, and returns true if
549 // successful.
550 virtual bool GetAccessibleKeyboardShortcut(std::wstring* shortcut) {
551 return false;
552 }
553
554 // Returns a brief, identifying string, containing a unique, readable name of
555 // a given control. Sets the input string appropriately, and returns true if
556 // successful.
557 virtual bool GetAccessibleName(std::wstring* name) { return false; }
558
559 // Returns the MSAA role of the current view. The role is what assistive
560 // technologies (ATs) use to determine what behavior to expect from a given
561 // control. Sets the input VARIANT appropriately, and returns true if
562 // successful.
563 virtual bool GetAccessibleRole(VARIANT* role) { return false; }
564
565 // Returns the MSAA state of the current view. Sets the input VARIANT
566 // appropriately, and returns true if a change was performed successfully.
567 virtual bool GetAccessibleState(VARIANT* state) { return false; }
568
569 // Assigns a keyboard shortcut string description to the given control. Needed
570 // as a View does not know which shortcut will be associated with it until it
571 // is created to be a certain type.
572 virtual void SetAccessibleKeyboardShortcut(const std::wstring& shortcut) {}
573
574 // Assigns a string name to the given control. Needed as a View does not know
575 // which name will be associated with it until it is created to be a
576 // certain type.
577 virtual void SetAccessibleName(const std::wstring& name) {}
578
579 // Returns an instance of a wrapper class implementing the (platform-specific)
580 // accessibility interface for a given View. If one exists, it will be
581 // re-used, otherwise a new instance will be created.
582 AccessibleWrapper* GetAccessibleWrapper();
583
584 // Accessor used to determine if a child view (leaf) has accessibility focus.
585 // Returns NULL if there are no children, or if none of the children has
586 // accessibility focus.
587 virtual ChromeViews::View* GetAccFocusedChildView() { return NULL; }
588
589 // Floating views
590 //
591 // A floating view is a view that is used to paint a cell within a parent view
592 // Floating Views are painted using PaintFloatingView() above.
593 //
594 // Floating views can also be lazily created and attached to the view
595 // hierarchy to process events. To make this possible, each view is given an
596 // opportunity to create and attach a floating view right before an mouse
597 // event is processed.
598
599 // Retrieves the id for the floating view at the specified coordinates if any.
600 // Derived classes that use floating views should implement this method and
601 // return true if a view has been found and its id set in |id|.
602 virtual bool GetFloatingViewIDForPoint(int x, int y, int* id);
603
604 // Retrieves the ID of the floating view at the specified |position| and sets
605 // it in |id|.
606 // For positions NEXT and PREVIOUS, the specified |starting_id| is used as
607 // the origin, it is ignored for FIRST and LAST.
608 // Returns true if an ID was found, false otherwise.
609 // For CURRENT, the |starting_id| should be set in |id| and true returned if
610 // the |starting_id| is a valid floating view id.
611 // Derived classes that use floating views should implement this method and
612 // return a unique ID for each floating view.
613 // The default implementation always returns false.
614 virtual bool EnumerateFloatingViews(FloatingViewPosition position,
615 int starting_id,
616 int* id);
617
618 // Creates and attaches the floating view with the specified |id| to this view
619 // hierarchy and returns it.
620 // Derived classes that use floating views should implement this method.
621 //
622 // NOTE: subclasses implementing this should return NULL if passed an invalid
623 // id. An invalid ID may be passed in by the focus manager when attempting
624 // to restore focus.
625 virtual View* ValidateFloatingViewForID(int id);
626
627 // Whether the focus should automatically be restored to the last focused
628 // view. Default implementation returns true.
629 // Derived classes that want to restore focus themselves should override this
630 // method and return false.
631 virtual bool ShouldRestoreFloatingViewFocus();
632
633 // Attach a floating view to the receiving view. The view is inserted
634 // in the child view list and will behave like a normal view. |id| is the
635 // floating view id for that view.
636 void AttachFloatingView(View* v, int id);
637
638 // Return whether a view already has a floating view which bounds intersects
639 // the provided point.
640 //
641 // If the View uses right-to-left UI layout, then the given point is checked
642 // against the mirrored position of each floating View.
643 bool HasFloatingViewForPoint(int x, int y);
644
645 // Detach and delete all floating views. Call this method when your model
646 // or layout changes.
647 void DetachAllFloatingViews();
648
649 // Returns the view with the specified |id|, by calling
650 // ValidateFloatingViewForID if that view has not yet been attached.
651 virtual View* RetrieveFloatingViewForID(int id);
652
653 // Restores the focus to the previously selected floating view.
654 virtual void RestoreFloatingViewFocus();
655
656 // Goes up the parent hierarchy of this view and returns the first floating
657 // view found. Returns NULL if none were found.
658 View* RetrieveFloatingViewParent();
659
660 // Utility functions
661
662 // Note that the utility coordinate conversions functions always operate on
663 // the mirrored position of the child Views if the parent View uses a
664 // right-to-left UI layout.
665
666 // Convert a point from source coordinate system to dst coordinate system.
667 //
668 // source is a parent or a child of dst, directly or transitively.
669 // If source and dst are not in the same View hierarchy, the result is
670 // undefined.
671 // Source can be NULL in which case it means the screen coordinate system
672 static void ConvertPointToView(View* src,
673 View* dst,
674 gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29675
676 // Convert a point from the coordinate system of a View to that of the
677 // ViewContainer. This is useful for example when sizing HWND children
678 // of the ViewContainer that don't know about the View hierarchy and need
679 // to be placed relative to the ViewContainer that is their parent.
[email protected]96b667d2008-10-14 20:58:44680 static void ConvertPointToViewContainer(View* src, gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29681
682 // Convert a point from a view ViewContainer to a View dest
[email protected]96b667d2008-10-14 20:58:44683 static void ConvertPointFromViewContainer(View *dest, gfx::Point* p);
initial.commit09911bf2008-07-26 23:55:29684
685 // Convert a point from the coordinate system of a View to that of the
686 // screen. This is useful for example when placing popup windows.
[email protected]96b667d2008-10-14 20:58:44687 static void ConvertPointToScreen(View* src, gfx::Point* point);
initial.commit09911bf2008-07-26 23:55:29688
689 // Event Handlers
690
691 // This method is invoked when the user clicks on this view.
692 // The provided event is in the receiver's coordinate system.
693 //
694 // Return true if you processed the event and want to receive subsequent
695 // MouseDraggged and MouseReleased events. This also stops the event from
696 // bubbling. If you return false, the event will bubble through parent
697 // views.
698 //
699 // If you remove yourself from the tree while processing this, event bubbling
700 // stops as if you returned true, but you will not receive future events.
701 // The return value is ignored in this case.
702 //
703 // Default implementation returns true if a ContextMenuController has been
704 // set, false otherwise. Override as needed.
705 //
706 virtual bool OnMousePressed(const MouseEvent& event);
707
708 // This method is invoked when the user clicked on this control.
709 // and is still moving the mouse with a button pressed.
710 // The provided event is in the receiver's coordinate system.
711 //
712 // Return true if you processed the event and want to receive
713 // subsequent MouseDragged and MouseReleased events.
714 //
715 // Default implementation returns true if a ContextMenuController has been
716 // set, false otherwise. Override as needed.
717 //
718 virtual bool OnMouseDragged(const MouseEvent& event);
719
720 // This method is invoked when the user releases the mouse
721 // button. The event is in the receiver's coordinate system.
722 //
723 // If canceled is true it indicates the mouse press/drag was canceled by a
724 // system/user gesture.
725 //
726 // Default implementation notifies the ContextMenuController is appropriate.
727 // Subclasses that wish to honor the ContextMenuController should invoke
728 // super.
729 virtual void OnMouseReleased(const MouseEvent& event, bool canceled);
730
731 // This method is invoked when the mouse is above this control
732 // The event is in the receiver's coordinate system.
733 //
734 // Default implementation does nothing. Override as needed.
735 virtual void OnMouseMoved(const MouseEvent& e);
736
737 // This method is invoked when the mouse enters this control.
738 //
739 // Default implementation does nothing. Override as needed.
740 virtual void OnMouseEntered(const MouseEvent& event);
741
742 // This method is invoked when the mouse exits this control
743 // The provided event location is always (0, 0)
744 // Default implementation does nothing. Override as needed.
745 virtual void OnMouseExited(const MouseEvent& event);
746
747 // Set the MouseHandler for a drag session.
748 //
749 // A drag session is a stream of mouse events starting
750 // with a MousePressed event, followed by several MouseDragged
751 // events and finishing with a MouseReleased event.
752 //
753 // This method should be only invoked while processing a
754 // MouseDragged or MouseReleased event.
755 //
756 // All further mouse dragged and mouse up events will be sent
757 // the MouseHandler, even if it is reparented to another window.
758 //
759 // The MouseHandler is automatically cleared when the control
760 // comes back from processing the MouseReleased event.
761 //
762 // Note: if the mouse handler is no longer connected to a
763 // view hierarchy, events won't be sent.
764 //
765 virtual void SetMouseHandler(View* new_mouse_handler);
766
767 // Request the keyboard focus. The receiving view will become the
768 // focused view.
769 virtual void RequestFocus();
770
771 // Invoked when a view is about to gain focus
772 virtual void WillGainFocus();
773
774 // Invoked when a view just gained focus.
775 virtual void DidGainFocus();
776
777 // Invoked when a view is about lose focus
778 virtual void WillLoseFocus();
779
780 // Invoked when a view is about to be requested for focus due to the focus
781 // traversal. Reverse is this request was generated going backward
782 // (Shift-Tab).
783 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) { }
784
785 // Invoked when a key is pressed or released.
786 // Subclasser should return true if the event has been processed and false
787 // otherwise. If the event has not been processed, the parent will be given a
788 // chance.
789 virtual bool OnKeyPressed(const KeyEvent& e);
790 virtual bool OnKeyReleased(const KeyEvent& e);
791
792 // Whether the view wants to receive Tab and Shift-Tab key events.
793 // If false, Tab and Shift-Tabs key events are used for focus traversal and
794 // are not sent to the view. If true, the events are sent to the view and not
795 // used for focus traversal.
796 // This implementation returns false (so that by default views handle nicely
797 // the keyboard focus traversal).
798 virtual bool CanProcessTabKeyEvents();
799
800 // Invoked when the user uses the mousewheel. Implementors should return true
801 // if the event has been processed and false otherwise. This message is sent
802 // if the view is focused. If the event has not been processed, the parent
803 // will be given a chance.
804 virtual bool OnMouseWheel(const MouseWheelEvent& e);
805
806 // Drag and drop functions.
807
808 // Set/get the DragController. See description of DragController for more
809 // information.
810 void SetDragController(DragController* drag_controller);
811 DragController* GetDragController();
812
813 // During a drag and drop session when the mouse moves the view under the
814 // mouse is queried to see if it should be a target for the drag and drop
815 // session. A view indicates it is a valid target by returning true from
816 // CanDrop. If a view returns true from CanDrop,
817 // OnDragEntered is sent to the view when the mouse first enters the view,
818 // as the mouse moves around within the view OnDragUpdated is invoked.
819 // If the user releases the mouse over the view and OnDragUpdated returns a
820 // valid drop, then OnPerformDrop is invoked. If the mouse moves outside the
821 // view or over another view that wants the drag, OnDragExited is invoked.
822 //
823 // Similar to mouse events, the deepest view under the mouse is first checked
824 // if it supports the drop (Drop). If the deepest view under
825 // the mouse does not support the drop, the ancestors are walked until one
826 // is found that supports the drop.
827
828 // A view that supports drag and drop must override this and return true if
829 // data contains a type that may be dropped on this view.
830 virtual bool CanDrop(const OSExchangeData& data);
831
832 // OnDragEntered is invoked when the mouse enters this view during a drag and
833 // drop session and CanDrop returns true. This is immediately
834 // followed by an invocation of OnDragUpdated, and eventually one of
835 // OnDragExited or OnPerformDrop.
836 virtual void OnDragEntered(const DropTargetEvent& event);
837
838 // Invoked during a drag and drop session while the mouse is over the view.
839 // This should return a bitmask of the DragDropTypes::DragOperation supported
840 // based on the location of the event. Return 0 to indicate the drop should
841 // not be accepted.
842 virtual int OnDragUpdated(const DropTargetEvent& event);
843
844 // Invoked during a drag and drop session when the mouse exits the views, or
845 // when the drag session was canceled and the mouse was over the view.
846 virtual void OnDragExited();
847
848 // Invoked during a drag and drop session when OnDragUpdated returns a valid
849 // operation and the user release the mouse.
850 virtual int OnPerformDrop(const DropTargetEvent& event);
851
852 // Returns true if the mouse was dragged enough to start a drag operation.
853 // delta_x and y are the distance the mouse was dragged.
854 static bool ExceededDragThreshold(int delta_x, int delta_y);
855
856 // This method is the main entry point to process paint for this
857 // view and its children. This method is called by the painting
858 // system. You should call this only if you want to draw a sub tree
859 // inside a custom graphics.
860 // To customize painting override either the Paint or PaintChildren method,
861 // not this one.
862 virtual void ProcessPaint(ChromeCanvas* canvas);
863
864 // Paint the View's child Views, in reverse order.
865 virtual void PaintChildren(ChromeCanvas* canvas);
866
867 // Sets the ContextMenuController. Setting this to non-null makes the View
868 // process mouse events.
869 void SetContextMenuController(ContextMenuController* menu_controller);
870 ContextMenuController* GetContextMenuController() {
871 return context_menu_controller_;
872 }
873
874 // Set the background. The background is owned by the view after this call.
875 virtual void SetBackground(Background* b);
876
877 // Return the background currently in use or NULL.
878 virtual const Background* GetBackground() const;
879
880 // Set the border. The border is owned by the view after this call.
881 virtual void SetBorder(Border* b);
882
883 // Return the border currently in use or NULL.
884 virtual const Border* GetBorder() const;
885
886 // Returns the insets of the current border. If there is no border an empty
887 // insets is returned.
888 gfx::Insets GetInsets() const;
889
890 // Return the cursor that should be used for this view or NULL if
891 // the default cursor should be used. The provided point is in the
892 // receiver's coordinate system.
893 virtual HCURSOR GetCursorForPoint(Event::EventType event_type, int x, int y);
894
895 // Convenience to test whether a point is within this view's bounds
[email protected]613b8062008-10-14 23:45:09896 virtual bool HitTest(const gfx::Point& l) const;
initial.commit09911bf2008-07-26 23:55:29897
898 // Gets the tooltip for this View. If the View does not have a tooltip,
899 // return false. If the View does have a tooltip, copy the tooltip into
900 // the supplied string and return true.
901 // Any time the tooltip text that a View is displaying changes, it must
902 // invoke TooltipTextChanged.
903 // The x/y provide the coordinates of the mouse (relative to this view).
904 virtual bool GetTooltipText(int x, int y, std::wstring* tooltip);
905
906 // Returns the location (relative to this View) for the text on the tooltip
907 // to display. If false is returned (the default), the tooltip is placed at
908 // a default position.
909 virtual bool GetTooltipTextOrigin(int x, int y, CPoint* loc);
910
911 // Set whether this view is owned by its parent. A view that is owned by its
912 // parent is automatically deleted when the parent is deleted. The default is
913 // true. Set to false if the view is owned by another object and should not
914 // be deleted by its parent.
915 void SetParentOwned(bool f);
916
917 // Return whether a view is owned by its parent. See SetParentOwned()
918 bool IsParentOwned() const;
919
920 // Return the receiving view's class name. A view class is a string which
921 // uniquely identifies the view class. It is intended to be used as a way to
922 // find out during run time if a view can be safely casted to a specific view
923 // subclass. The default implementation returns kViewClassName.
924 virtual std::string GetClassName() const;
925
926 // Returns the visible bounds of the receiver in the receivers coordinate
927 // system.
928 //
929 // When traversing the View hierarchy in order to compute the bounds, the
930 // function takes into account the mirroring setting for each View and
931 // therefore it will return the mirrored version of the visible bounds if
932 // need be.
933 gfx::Rect GetVisibleBounds();
934
935 // Subclasses that contain traversable children that are not directly
936 // accessible through the children hierarchy should return the associated
937 // FocusTraversable for the focus traversal to work properly.
938 virtual FocusTraversable* GetFocusTraversable() { return NULL; }
939
940#ifndef NDEBUG
941 // Debug method that logs the view hierarchy to the output.
942 void PrintViewHierarchy();
943
944 // Debug method that logs the focus traversal hierarchy to the output.
945 void PrintFocusHierarchy();
946#endif
947
948 // The following methods are used by ScrollView to determine the amount
949 // to scroll relative to the visible bounds of the view. For example, a
950 // return value of 10 indicates the scrollview should scroll 10 pixels in
951 // the appropriate direction.
952 //
953 // Each method takes the following parameters:
954 //
955 // is_horizontal: if true, scrolling is along the horizontal axis, otherwise
956 // the vertical axis.
957 // is_positive: if true, scrolling is by a positive amount. Along the
958 // vertical axis scrolling by a positive amount equates to
959 // scrolling down.
960 //
961 // The return value should always be positive and gives the number of pixels
962 // to scroll. ScrollView interprets a return value of 0 (or negative)
963 // to scroll by a default amount.
964 //
965 // See VariableRowHeightScrollHelper and FixedRowHeightScrollHelper for
966 // implementations of common cases.
967 virtual int GetPageScrollIncrement(ScrollView* scroll_view,
968 bool is_horizontal, bool is_positive);
969 virtual int GetLineScrollIncrement(ScrollView* scroll_view,
970 bool is_horizontal, bool is_positive);
971
972 protected:
[email protected]82739cf2008-09-16 00:37:56973 // TODO(beng): these members should NOT be protected per style guide.
initial.commit09911bf2008-07-26 23:55:29974 // This View's bounds in the parent coordinate system.
975 CRect bounds_;
976
977 // The id of this View. Used to find this View.
978 int id_;
979
980 // The group of this view. Some view subclasses use this id to find other
981 // views of the same group. For example radio button uses this information
982 // to find other radio buttons.
983 int group_;
984
985#ifndef NDEBUG
986 // Returns true if the View is currently processing a paint.
987 virtual bool IsProcessingPaint() const;
988#endif
989
[email protected]82739cf2008-09-16 00:37:56990 // Called by HitTest to see if this View has a custom hit test mask. If the
991 // return value is true, GetHitTestMask will be called to obtain the mask.
992 // Default value is false, in which case the View will hit-test against its
993 // bounds.
994 virtual bool HasHitTestMask() const;
995
996 // Called by HitTest to retrieve a mask for hit-testing against. Subclasses
997 // override to provide custom shaped hit test regions.
998 virtual void GetHitTestMask(gfx::Path* mask) const;
999
initial.commit09911bf2008-07-26 23:55:291000 // This method is invoked when the tree changes.
1001 //
1002 // When a view is removed, it is invoked for all children and grand
1003 // children. For each of these views, a notification is sent to the
1004 // view and all parents.
1005 //
1006 // When a view is added, a notification is sent to the view, all its
1007 // parents, and all its children (and grand children)
1008 //
1009 // Default implementation does nothing. Override to perform operations
1010 // required when a view is added or removed from a view hierarchy
1011 //
1012 // parent is the new or old parent. Child is the view being added or
1013 // removed.
1014 //
1015 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
1016
1017 // When SetVisible() changes the visibility of a view, this method is
1018 // invoked for that view as well as all the children recursively.
1019 virtual void VisibilityChanged(View* starting_from, bool is_visible);
1020
1021 // Views must invoke this when the tooltip text they are to display changes.
1022 void TooltipTextChanged();
1023
1024 // Actual implementation of GetViewForPoint.
[email protected]613b8062008-10-14 23:45:091025 virtual View* GetViewForPoint(const gfx::Point& point,
1026 bool can_create_floating);
initial.commit09911bf2008-07-26 23:55:291027
1028 // Sets whether this view wants notification when its visible bounds relative
1029 // to the root view changes. If true, this view is notified any time the
1030 // origin of one its ancestors changes, or the portion of the bounds not
1031 // obscured by ancestors changes. The default is false.
1032 void SetNotifyWhenVisibleBoundsInRootChanges(bool value);
1033 bool GetNotifyWhenVisibleBoundsInRootChanges();
1034
1035 // Notification that this views visible bounds, relative to the RootView
1036 // has changed. The visible bounds corresponds to the region of the
1037 // view not obscured by other ancestors.
1038 virtual void VisibleBoundsInRootChanged() {}
1039
1040 // Sets the keyboard focus to this View. The correct way to set the focus is
1041 // to call RequestFocus() on the view. This method is called when the focus is
1042 // set and gives an opportunity to subclasses to perform any extra focus steps
1043 // (for example native component set the native focus on their native
1044 // component). The default behavior is to set the native focus on the root
1045 // view container, which is what is appropriate for views that have no native
1046 // window associated with them (so the root view gets the keyboard messages).
1047 virtual void Focus();
1048
1049 // Heavyweight views (views that hold a native control) should return the
1050 // window for that control.
1051 virtual HWND GetNativeControlHWND() { return NULL; }
1052
1053 // Invoked when a key is pressed before the key event is processed by the
1054 // focus manager for accelerators. This gives a chance to the view to
1055 // override an accelerator. Subclasser should return false if they want to
1056 // process the key event and not have it translated to an accelerator (if
1057 // any). In that case, OnKeyPressed will subsequently be invoked for that
1058 // event.
1059 virtual bool ShouldLookupAccelerators(const KeyEvent& e) { return true; }
1060
1061 // A convenience method for derived classes which have floating views with IDs
1062 // that are consecutive numbers in an interval [|low_bound|, |high_bound|[.
1063 // They can call this method in their EnumerateFloatingViews implementation.
1064 // If |ascending_order| is true, the first id is |low_bound|, the next after
1065 // id n is n + 1, and so on. If |ascending_order| is false, the order is
1066 // reversed, first id is |high_bound|, the next id after id n is n -1...
1067 static bool EnumerateFloatingViewsForInterval(int low_bound, int high_bound,
1068 bool ascending_order,
1069 FloatingViewPosition position,
1070 int starting_id,
1071 int* id);
1072
1073 // These are cover methods that invoke the method of the same name on
1074 // the DragController. Subclasses may wish to override rather than install
1075 // a DragController.
1076 // See DragController for a description of these methods.
1077 virtual int GetDragOperations(int press_x, int press_y);
1078 virtual void WriteDragData(int press_x, int press_y, OSExchangeData* data);
1079
1080 // Invoked from DoDrag after the drag completes. This implementation does
1081 // nothing, and is intended for subclasses to do cleanup.
1082 virtual void OnDragDone();
1083
1084 // Returns whether we're in the middle of a drag session that was initiated
1085 // by us.
1086 bool InDrag();
1087
1088 // Whether this view is enabled.
1089 bool enabled_;
1090
1091 // Whether the view can be focused.
1092 bool focusable_;
1093
1094 private:
1095 friend class RootView;
1096 friend class FocusManager;
1097 friend class ViewStorage;
1098
1099 // Used to track a drag. RootView passes this into
1100 // ProcessMousePressed/Dragged.
1101 struct DragInfo {
1102 // Sets possible_drag to false and start_x/y to 0. This is invoked by
1103 // RootView prior to invoke ProcessMousePressed.
1104 void Reset();
1105
1106 // Sets possible_drag to true and start_x/y to the specified coordinates.
1107 // This is invoked by the target view if it detects the press may generate
1108 // a drag.
1109 void PossibleDrag(int x, int y);
1110
1111 // Whether the press may generate a drag.
1112 bool possible_drag;
1113
1114 // Coordinates of the mouse press.
1115 int start_x;
1116 int start_y;
1117 };
1118
1119 // RootView invokes these. These in turn invoke the appropriate OnMouseXXX
1120 // method. If a drag is detected, DoDrag is invoked.
1121 bool ProcessMousePressed(const MouseEvent& e, DragInfo* drop_info);
1122 bool ProcessMouseDragged(const MouseEvent& e, DragInfo* drop_info);
1123 void ProcessMouseReleased(const MouseEvent& e, bool canceled);
1124
1125 // Starts a drag and drop operation originating from this view. This invokes
1126 // WriteDragData to write the data and GetDragOperations to determine the
1127 // supported drag operations. When done, OnDragDone is invoked.
1128 void DoDrag(const ChromeViews::MouseEvent& e, int press_x, int press_y);
1129
1130 // Adds a child View at the specified position. |floating_view| should be true
1131 // if the |v| is a floating view.
1132 void AddChildView(int index, View* v, bool floating_view);
1133
1134 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true,
1135 // the next and previous focusable views of views pointing to this view are
1136 // updated. If |update_tool_tip| is true, the tooltip is updated. If
1137 // |delete_removed_view| is true, the view is also deleted (if it is parent
1138 // owned).
1139 void DoRemoveChildView(View* view,
1140 bool update_focus_cycle,
1141 bool update_tool_tip,
1142 bool delete_removed_view);
1143
1144 // Sets the parent View. This is called automatically by AddChild and is
1145 // thus private.
1146 void SetParent(View *parent);
1147
1148 // Call ViewHierarchyChanged for all child views on all parents
1149 void PropagateRemoveNotifications(View* parent);
1150
1151 // Call ViewHierarchyChanged for all children
1152 void PropagateAddNotifications(View* parent, View* child);
1153
1154 // Call VisibilityChanged() recursively for all children.
1155 void PropagateVisibilityNotifications(View* from, bool is_visible);
1156
1157 // Takes care of registering/unregistering accelerators if
1158 // |register_accelerators| true and calls ViewHierarchyChanged().
1159 void ViewHierarchyChangedImpl(bool register_accelerators,
1160 bool is_add, View *parent, View *child);
1161
1162 // This is the actual implementation for ConvertPointToView()
1163 // Attempts a parent -> child conversion and then a
1164 // child -> parent conversion if try_other_direction is true
1165 static void ConvertPointToView(View* src,
1166 View *dst,
1167 gfx::Point* point,
1168 bool try_other_direction);
1169
1170 // Propagates UpdateTooltip() to the TooltipManager for the ViewContainer.
1171 // This must be invoked any time the View hierarchy changes in such a way
1172 // the view under the mouse differs. For example, if the bounds of a View is
1173 // changed, this is invoked. Similarly, as Views are added/removed, this
1174 // is invoked.
1175 void UpdateTooltip();
1176
1177 // Recursively descends through all descendant views,
1178 // registering/unregistering all views that want visible bounds in root
1179 // view notification.
1180 static void RegisterChildrenForVisibleBoundsNotification(RootView* root,
1181 View* view);
1182 static void UnregisterChildrenForVisibleBoundsNotification(RootView* root,
1183 View* view);
1184
1185 // Adds/removes view to the list of descendants that are notified any time
1186 // this views location and possibly size are changed.
1187 void AddDescendantToNotify(View* view);
1188 void RemoveDescendantToNotify(View* view);
1189
1190 // Initialize the previous/next focusable views of the specified view relative
1191 // to the view at the specified index.
1192 void InitFocusSiblings(View* view, int index);
1193
1194 // Actual implementation of PrintFocusHierarchy.
1195 void PrintViewHierarchyImp(int indent);
1196 void PrintFocusHierarchyImp(int indent);
1197
1198 // Registers/unregister this view's keyboard accelerators with the
1199 // FocusManager.
1200 void RegisterAccelerators();
1201 void UnregisterAccelerators();
1202
1203 // Returns the number of children that are actually attached floating views.
1204 int GetFloatingViewCount() const;
1205
1206 // Returns the id for this floating view.
1207 int GetFloatingViewID();
1208
1209 // Returns whether this view is a floating view.
1210 bool IsFloatingView();
1211
1212 // Sets in |path| the path in the view hierarchy from |start| to |end| (the
1213 // path is the list of indexes in each view's children to get from |start|
1214 // to |end|).
1215 // Returns true if |start| and |view| are connected and the |path| has been
1216 // retrieved succesfully, false otherwise.
1217 static bool GetViewPath(View* start, View* end, std::vector<int>* path);
1218
1219 // Returns the view at the end of the specified |path|, starting at the
1220 // |start| view.
1221 static View* GetViewForPath(View* start, const std::vector<int>& path);
1222
1223 // This view's parent
1224 View *parent_;
1225
1226 // This view's children.
1227 typedef std::vector<View*> ViewList;
1228 ViewList child_views_;
1229
1230 // List of floating children. A floating view is always referenced by
1231 // child_views_ and will be deleted on destruction just like any other
1232 // child view.
1233 ViewList floating_views_;
1234
1235 // Maps a floating view to its floating view id.
1236 std::map<View*, int> floating_views_ids_;
1237
1238 // Whether we want the focus to be restored. This is used to store/restore
1239 // focus for floating views.
1240 bool should_restore_focus_;
1241
1242 // The View's LayoutManager defines the sizing heuristics applied to child
1243 // Views. The default is absolute positioning according to bounds_.
1244 scoped_ptr<LayoutManager> layout_manager_;
1245
1246 // Visible state
1247 bool is_visible_;
1248
1249 // Background
1250 Background* background_;
1251
1252 // Border.
1253 Border* border_;
1254
1255 // Whether this view is owned by its parent.
1256 bool is_parent_owned_;
1257
1258 // See SetNotifyWhenVisibleBoundsInRootChanges.
1259 bool notify_when_visible_bounds_in_root_changes_;
1260
1261 // Whether or not RegisterViewForVisibleBoundsNotification on the RootView
1262 // has been invoked.
1263 bool registered_for_visible_bounds_notification_;
1264
1265 // List of descendants wanting notification when their visible bounds change.
1266 scoped_ptr<ViewList> descendants_to_notify_;
1267
1268 // Next view to be focused when the Tab key is pressed.
1269 View* next_focusable_view_;
1270
1271 // Next view to be focused when the Shift-Tab key combination is pressed.
1272 View* previous_focusable_view_;
1273
1274 // The list of accelerators.
[email protected]1eb89e82008-08-15 12:27:031275 scoped_ptr<std::vector<Accelerator> > accelerators_;
initial.commit09911bf2008-07-26 23:55:291276
1277 // The task used to restore automatically the focus to the last focused
1278 // floating view.
1279 RestoreFocusTask* restore_focus_view_task_;
1280
1281 // The menu controller.
1282 ContextMenuController* context_menu_controller_;
1283
1284 // The accessibility implementation for this View.
1285 scoped_ptr<AccessibleWrapper> accessibility_;
1286
1287 DragController* drag_controller_;
1288
1289 // Indicates whether or not the view is going to be mirrored (that is, use a
1290 // right-to-left UI layout) if the locale's language is a right-to-left
1291 // language like Arabic or Hebrew.
1292 bool ui_mirroring_is_enabled_for_rtl_languages_;
1293
1294 // Indicates whether or not the ChromeCanvas object passed to View::Paint()
1295 // is going to be flipped horizontally (using the appropriate transform) on
1296 // right-to-left locales for this View.
1297 bool flip_canvas_on_paint_for_rtl_ui_;
1298
[email protected]1eb89e82008-08-15 12:27:031299 DISALLOW_COPY_AND_ASSIGN(View);
initial.commit09911bf2008-07-26 23:55:291300};
1301
[email protected]1eb89e82008-08-15 12:27:031302} // namespace ChromeViews
initial.commit09911bf2008-07-26 23:55:291303
[email protected]1eb89e82008-08-15 12:27:031304#endif // CHROME_VIEWS_VIEW_H_
license.botbf09a502008-08-24 00:55:551305