OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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. | |
4 | |
5 #ifndef VIEWS_VIEW_H_ | |
6 #define VIEWS_VIEW_H_ | |
7 #pragma once | |
8 | |
9 #include <algorithm> | |
10 #include <map> | |
11 #include <set> | |
12 #include <string> | |
13 #include <vector> | |
14 | |
15 #include "base/compiler_specific.h" | |
16 #include "base/i18n/rtl.h" | |
17 #include "base/logging.h" | |
18 #include "base/memory/scoped_ptr.h" | |
19 #include "build/build_config.h" | |
20 #include "ui/base/accelerators/accelerator.h" | |
21 #include "ui/base/dragdrop/os_exchange_data.h" | |
22 #include "ui/gfx/compositor/layer_delegate.h" | |
23 #include "ui/gfx/native_widget_types.h" | |
24 #include "ui/gfx/rect.h" | |
25 #include "ui/views/events/event.h" | |
26 #include "views/background.h" | |
27 #include "views/border.h" | |
28 | |
29 #if defined(OS_WIN) | |
30 #include "base/win/scoped_comptr.h" | |
31 #endif | |
32 | |
33 using ui::OSExchangeData; | |
34 | |
35 namespace gfx { | |
36 class Canvas; | |
37 class Insets; | |
38 class Path; | |
39 } | |
40 | |
41 namespace ui { | |
42 struct AccessibleViewState; | |
43 class Compositor; | |
44 class Layer; | |
45 class TextInputClient; | |
46 class Texture; | |
47 class ThemeProvider; | |
48 class Transform; | |
49 enum TouchStatus; | |
50 } | |
51 | |
52 #if defined(OS_WIN) | |
53 class __declspec(uuid("26f5641a-246d-457b-a96d-07f3fae6acf2")) | |
54 NativeViewAccessibilityWin; | |
55 #endif | |
56 | |
57 namespace views { | |
58 | |
59 class Background; | |
60 class Border; | |
61 class ContextMenuController; | |
62 class DragController; | |
63 class FocusManager; | |
64 class FocusTraversable; | |
65 class InputMethod; | |
66 class LayoutManager; | |
67 class ScrollView; | |
68 class Widget; | |
69 | |
70 namespace internal { | |
71 class NativeWidgetView; | |
72 class RootView; | |
73 } | |
74 | |
75 ///////////////////////////////////////////////////////////////////////////// | |
76 // | |
77 // View class | |
78 // | |
79 // A View is a rectangle within the views View hierarchy. It is the base | |
80 // class for all Views. | |
81 // | |
82 // A View is a container of other Views (there is no such thing as a Leaf | |
83 // View - makes code simpler, reduces type conversion headaches, design | |
84 // mistakes etc) | |
85 // | |
86 // The View contains basic properties for sizing (bounds), layout (flex, | |
87 // orientation, etc), painting of children and event dispatch. | |
88 // | |
89 // The View also uses a simple Box Layout Manager similar to XUL's | |
90 // SprocketLayout system. Alternative Layout Managers implementing the | |
91 // LayoutManager interface can be used to lay out children if required. | |
92 // | |
93 // It is up to the subclass to implement Painting and storage of subclass - | |
94 // specific properties and functionality. | |
95 // | |
96 // Unless otherwise documented, views is not thread safe and should only be | |
97 // accessed from the main thread. | |
98 // | |
99 ///////////////////////////////////////////////////////////////////////////// | |
100 class VIEWS_EXPORT View : public ui::LayerDelegate, | |
101 public ui::AcceleratorTarget { | |
102 public: | |
103 typedef std::vector<View*> Views; | |
104 | |
105 // TO BE MOVED --------------------------------------------------------------- | |
106 // TODO(beng): These methods are to be moved to other files/classes. | |
107 | |
108 // TODO(beng): delete | |
109 // Set whether this view is hottracked. A disabled view cannot be hottracked. | |
110 // If flag differs from the current value, SchedulePaint is invoked. | |
111 virtual void SetHotTracked(bool flag); | |
112 | |
113 // TODO(beng): delete | |
114 // Returns whether the view is hot-tracked. | |
115 virtual bool IsHotTracked() const; | |
116 | |
117 // Creation and lifetime ----------------------------------------------------- | |
118 | |
119 View(); | |
120 virtual ~View(); | |
121 | |
122 // By default a View is owned by its parent unless specified otherwise here. | |
123 bool parent_owned() const { return parent_owned_; } | |
124 void set_parent_owned(bool parent_owned) { parent_owned_ = parent_owned; } | |
125 | |
126 // Tree operations ----------------------------------------------------------- | |
127 | |
128 // Get the Widget that hosts this View, if any. | |
129 virtual const Widget* GetWidget() const; | |
130 virtual Widget* GetWidget(); | |
131 | |
132 // Adds |view| as a child of this view, optionally at |index|. | |
133 void AddChildView(View* view); | |
134 void AddChildViewAt(View* view, int index); | |
135 | |
136 // Moves |view| to the specified |index|. A negative value for |index| moves | |
137 // the view at the end. | |
138 void ReorderChildView(View* view, int index); | |
139 | |
140 // Removes |view| from this view. The view's parent will change to NULL. | |
141 void RemoveChildView(View* view); | |
142 | |
143 // Removes all the children from this view. If |delete_children| is true, | |
144 // the views are deleted, unless marked as not parent owned. | |
145 void RemoveAllChildViews(bool delete_children); | |
146 | |
147 // STL-style accessors. | |
148 Views::const_iterator children_begin() { return children_.begin(); } | |
149 Views::const_iterator children_end() { return children_.end(); } | |
150 Views::const_reverse_iterator children_rbegin() { return children_.rbegin(); } | |
151 Views::const_reverse_iterator children_rend() { return children_.rend(); } | |
152 int child_count() const { return static_cast<int>(children_.size()); } | |
153 bool has_children() const { return !children_.empty(); } | |
154 | |
155 // Returns the child view at |index|. | |
156 const View* child_at(int index) const { | |
157 DCHECK_GE(index, 0); | |
158 DCHECK_LT(index, child_count()); | |
159 return children_[index]; | |
160 } | |
161 View* child_at(int index) { | |
162 return const_cast<View*>(const_cast<const View*>(this)->child_at(index)); | |
163 } | |
164 | |
165 // Returns the parent view. | |
166 const View* parent() const { return parent_; } | |
167 View* parent() { return parent_; } | |
168 | |
169 // Returns true if |view| is contained within this View's hierarchy, even as | |
170 // an indirect descendant. Will return true if child is also this view. | |
171 bool Contains(const View* view) const; | |
172 | |
173 // Returns the index of |view|, or -1 if |view| is not a child of this view. | |
174 int GetIndexOf(const View* view) const; | |
175 | |
176 // Size and disposition ------------------------------------------------------ | |
177 // Methods for obtaining and modifying the position and size of the view. | |
178 // Position is in the coordinate system of the view's parent. | |
179 // Position is NOT flipped for RTL. See "RTL positioning" for RTL-sensitive | |
180 // position accessors. | |
181 // Transformations are not applied on the size/position. For example, if | |
182 // bounds is (0, 0, 100, 100) and it is scaled by 0.5 along the X axis, the | |
183 // width will still be 100 (although when painted, it will be 50x50, painted | |
184 // at location (0, 0)). | |
185 | |
186 void SetBounds(int x, int y, int width, int height); | |
187 void SetBoundsRect(const gfx::Rect& bounds); | |
188 void SetSize(const gfx::Size& size); | |
189 void SetPosition(const gfx::Point& position); | |
190 void SetX(int x); | |
191 void SetY(int y); | |
192 | |
193 // No transformation is applied on the size or the locations. | |
194 const gfx::Rect& bounds() const { return bounds_; } | |
195 int x() const { return bounds_.x(); } | |
196 int y() const { return bounds_.y(); } | |
197 int width() const { return bounds_.width(); } | |
198 int height() const { return bounds_.height(); } | |
199 const gfx::Size& size() const { return bounds_.size(); } | |
200 | |
201 // Returns the bounds of the content area of the view, i.e. the rectangle | |
202 // enclosed by the view's border. | |
203 gfx::Rect GetContentsBounds() const; | |
204 | |
205 // Returns the bounds of the view in its own coordinates (i.e. position is | |
206 // 0, 0). | |
207 gfx::Rect GetLocalBounds() const; | |
208 | |
209 // Returns the insets of the current border. If there is no border an empty | |
210 // insets is returned. | |
211 virtual gfx::Insets GetInsets() const; | |
212 | |
213 // Returns the visible bounds of the receiver in the receivers coordinate | |
214 // system. | |
215 // | |
216 // When traversing the View hierarchy in order to compute the bounds, the | |
217 // function takes into account the mirroring setting and transformation for | |
218 // each View and therefore it will return the mirrored and transformed version | |
219 // of the visible bounds if need be. | |
220 gfx::Rect GetVisibleBounds() const; | |
221 | |
222 // Return the bounds of the View in screen coordinate system. | |
223 gfx::Rect GetScreenBounds() const; | |
224 | |
225 // Returns the baseline of this view, or -1 if this view has no baseline. The | |
226 // return value is relative to the preferred height. | |
227 virtual int GetBaseline() const; | |
228 | |
229 // Get the size the View would like to be, if enough space were available. | |
230 virtual gfx::Size GetPreferredSize(); | |
231 | |
232 // Convenience method that sizes this view to its preferred size. | |
233 void SizeToPreferredSize(); | |
234 | |
235 // Gets the minimum size of the view. View's implementation invokes | |
236 // GetPreferredSize. | |
237 virtual gfx::Size GetMinimumSize(); | |
238 | |
239 // Return the height necessary to display this view with the provided width. | |
240 // View's implementation returns the value from getPreferredSize.cy. | |
241 // Override if your View's preferred height depends upon the width (such | |
242 // as with Labels). | |
243 virtual int GetHeightForWidth(int w); | |
244 | |
245 // Set whether the receiving view is visible. Painting is scheduled as needed | |
246 virtual void SetVisible(bool visible); | |
247 | |
248 // Return whether a view is visible | |
249 virtual bool IsVisible() const; | |
250 | |
251 // Return whether a view and its ancestors are visible. Returns true if the | |
252 // path from this view to the root view is visible. | |
253 virtual bool IsVisibleInRootView() const; | |
254 | |
255 // Set whether this view is enabled. A disabled view does not receive keyboard | |
256 // or mouse inputs. If flag differs from the current value, SchedulePaint is | |
257 // invoked. | |
258 void SetEnabled(bool enabled); | |
259 | |
260 // Returns whether the view is enabled. | |
261 virtual bool IsEnabled() const; | |
262 | |
263 // This indicates that the view completely fills its bounds in an opaque | |
264 // color. This doesn't affect compositing but is a hint to the compositor to | |
265 // optimize painting. | |
266 // Note that this method does not implicitly create a layer if one does not | |
267 // already exist for the View, but is a no-op in that case. | |
268 void SetFillsBoundsOpaquely(bool fills_bounds_opaquely); | |
269 | |
270 // Transformations ----------------------------------------------------------- | |
271 | |
272 // Methods for setting transformations for a view (e.g. rotation, scaling). | |
273 | |
274 const ui::Transform& GetTransform() const; | |
275 | |
276 // Clipping parameters. Clipping happens from the right and/or bottom. The | |
277 // clipping amount is in parent's coordinate system, as in, if the view is | |
278 // rotated, then the clipping will be applied after the rotation (and other | |
279 // transformations, if any). | |
280 void set_clip_x(float x) { clip_x_ = x; } | |
281 void set_clip_y(float y) { clip_y_ = y; } | |
282 void set_clip(float x, float y) { clip_x_ = x; clip_y_ = y; } | |
283 | |
284 // Sets the transform to the supplied transform. | |
285 void SetTransform(const ui::Transform& transform); | |
286 | |
287 // Sets whether this view paints to a layer. A view paints to a layer if | |
288 // either of the following are true: | |
289 // . the view has a non-identity transform. | |
290 // . SetPaintToLayer(true) has been invoked. | |
291 // View creates the Layer only when it exists in a Widget with a non-NULL | |
292 // Compositor. | |
293 void SetPaintToLayer(bool paint_to_layer); | |
294 | |
295 const ui::Layer* layer() const { return layer_.get(); } | |
296 ui::Layer* layer() { return layer_.get(); } | |
297 | |
298 // RTL positioning ----------------------------------------------------------- | |
299 | |
300 // Methods for accessing the bounds and position of the view, relative to its | |
301 // parent. The position returned is mirrored if the parent view is using a RTL | |
302 // layout. | |
303 // | |
304 // NOTE: in the vast majority of the cases, the mirroring implementation is | |
305 // transparent to the View subclasses and therefore you should use the | |
306 // bounds() accessor instead. | |
307 gfx::Rect GetMirroredBounds() const; | |
308 gfx::Point GetMirroredPosition() const; | |
309 int GetMirroredX() const; | |
310 | |
311 // Given a rectangle specified in this View's coordinate system, the function | |
312 // computes the 'left' value for the mirrored rectangle within this View. If | |
313 // the View's UI layout is not right-to-left, then bounds.x() is returned. | |
314 // | |
315 // UI mirroring is transparent to most View subclasses and therefore there is | |
316 // no need to call this routine from anywhere within your subclass | |
317 // implementation. | |
318 int GetMirroredXForRect(const gfx::Rect& rect) const; | |
319 | |
320 // Given the X coordinate of a point inside the View, this function returns | |
321 // the mirrored X coordinate of the point if the View's UI layout is | |
322 // right-to-left. If the layout is left-to-right, the same X coordinate is | |
323 // returned. | |
324 // | |
325 // Following are a few examples of the values returned by this function for | |
326 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout: | |
327 // | |
328 // GetMirroredXCoordinateInView(0) -> 100 | |
329 // GetMirroredXCoordinateInView(20) -> 80 | |
330 // GetMirroredXCoordinateInView(99) -> 1 | |
331 int GetMirroredXInView(int x) const; | |
332 | |
333 // Given a X coordinate and a width inside the View, this function returns | |
334 // the mirrored X coordinate if the View's UI layout is right-to-left. If the | |
335 // layout is left-to-right, the same X coordinate is returned. | |
336 // | |
337 // Following are a few examples of the values returned by this function for | |
338 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout: | |
339 // | |
340 // GetMirroredXCoordinateInView(0, 10) -> 90 | |
341 // GetMirroredXCoordinateInView(20, 20) -> 60 | |
342 int GetMirroredXWithWidthInView(int x, int w) const; | |
343 | |
344 // Layout -------------------------------------------------------------------- | |
345 | |
346 // Lay out the child Views (set their bounds based on sizing heuristics | |
347 // specific to the current Layout Manager) | |
348 virtual void Layout(); | |
349 | |
350 // TODO(beng): I think we should remove this. | |
351 // Mark this view and all parents to require a relayout. This ensures the | |
352 // next call to Layout() will propagate to this view, even if the bounds of | |
353 // parent views do not change. | |
354 void InvalidateLayout(); | |
355 | |
356 // Gets/Sets the Layout Manager used by this view to size and place its | |
357 // children. | |
358 // The LayoutManager is owned by the View and is deleted when the view is | |
359 // deleted, or when a new LayoutManager is installed. | |
360 LayoutManager* GetLayoutManager() const; | |
361 void SetLayoutManager(LayoutManager* layout); | |
362 | |
363 // Attributes ---------------------------------------------------------------- | |
364 | |
365 // The view class name. | |
366 static const char kViewClassName[]; | |
367 | |
368 // Return the receiving view's class name. A view class is a string which | |
369 // uniquely identifies the view class. It is intended to be used as a way to | |
370 // find out during run time if a view can be safely casted to a specific view | |
371 // subclass. The default implementation returns kViewClassName. | |
372 virtual std::string GetClassName() const; | |
373 | |
374 // Returns the first ancestor, starting at this, whose class name is |name|. | |
375 // Returns null if no ancestor has the class name |name|. | |
376 View* GetAncestorWithClassName(const std::string& name); | |
377 | |
378 // Recursively descends the view tree starting at this view, and returns | |
379 // the first child that it encounters that has the given ID. | |
380 // Returns NULL if no matching child view is found. | |
381 virtual const View* GetViewByID(int id) const; | |
382 virtual View* GetViewByID(int id); | |
383 | |
384 // Gets and sets the ID for this view. ID should be unique within the subtree | |
385 // that you intend to search for it. 0 is the default ID for views. | |
386 int id() const { return id_; } | |
387 void set_id(int id) { id_ = id; } | |
388 | |
389 // A group id is used to tag views which are part of the same logical group. | |
390 // Focus can be moved between views with the same group using the arrow keys. | |
391 // Groups are currently used to implement radio button mutual exclusion. | |
392 // The group id is immutable once it's set. | |
393 void SetGroup(int gid); | |
394 // Returns the group id of the view, or -1 if the id is not set yet. | |
395 int GetGroup() const; | |
396 | |
397 // If this returns true, the views from the same group can each be focused | |
398 // when moving focus with the Tab/Shift-Tab key. If this returns false, | |
399 // only the selected view from the group (obtained with | |
400 // GetSelectedViewForGroup()) is focused. | |
401 virtual bool IsGroupFocusTraversable() const; | |
402 | |
403 // Fills |views| with all the available views which belong to the provided | |
404 // |group|. | |
405 void GetViewsInGroup(int group, Views* views); | |
406 | |
407 // Returns the View that is currently selected in |group|. | |
408 // The default implementation simply returns the first View found for that | |
409 // group. | |
410 virtual View* GetSelectedViewForGroup(int group); | |
411 | |
412 // Coordinate conversion ----------------------------------------------------- | |
413 | |
414 // Note that the utility coordinate conversions functions always operate on | |
415 // the mirrored position of the child Views if the parent View uses a | |
416 // right-to-left UI layout. | |
417 | |
418 // Convert a point from the coordinate system of one View to another. | |
419 // | |
420 // |source| and |target| must be in the same widget, but doesn't need to be in | |
421 // the same view hierarchy. | |
422 // |source| can be NULL in which case it means the screen coordinate system. | |
423 static void ConvertPointToView(const View* source, | |
424 const View* target, | |
425 gfx::Point* point); | |
426 | |
427 // Convert a point from a View's coordinate system to that of its Widget. | |
428 static void ConvertPointToWidget(const View* src, gfx::Point* point); | |
429 | |
430 // Convert a point from the coordinate system of a View's Widget to that | |
431 // View's coordinate system. | |
432 static void ConvertPointFromWidget(const View* dest, gfx::Point* p); | |
433 | |
434 // Convert a point from a View's coordinate system to that of the screen. | |
435 static void ConvertPointToScreen(const View* src, gfx::Point* point); | |
436 | |
437 // Applies transformation on the rectangle, which is in the view's coordinate | |
438 // system, to convert it into the parent's coordinate system. | |
439 gfx::Rect ConvertRectToParent(const gfx::Rect& rect) const; | |
440 | |
441 // Converts a rectangle from this views coordinate system to its widget | |
442 // coordinate system. | |
443 gfx::Rect ConvertRectToWidget(const gfx::Rect& rect) const; | |
444 | |
445 // Painting ------------------------------------------------------------------ | |
446 | |
447 // Mark all or part of the View's bounds as dirty (needing repaint). | |
448 // |r| is in the View's coordinates. | |
449 // Rectangle |r| should be in the view's coordinate system. The | |
450 // transformations are applied to it to convert it into the parent coordinate | |
451 // system before propagating SchedulePaint up the view hierarchy. | |
452 // TODO(beng): Make protected. | |
453 virtual void SchedulePaint(); | |
454 virtual void SchedulePaintInRect(const gfx::Rect& r); | |
455 | |
456 // Called by the framework to paint a View. Performs translation and clipping | |
457 // for View coordinates and language direction as required, allows the View | |
458 // to paint itself via the various OnPaint*() event handlers and then paints | |
459 // the hierarchy beneath it. | |
460 virtual void Paint(gfx::Canvas* canvas); | |
461 | |
462 // The background object is owned by this object and may be NULL. | |
463 void set_background(Background* b) { background_.reset(b); } | |
464 const Background* background() const { return background_.get(); } | |
465 Background* background() { return background_.get(); } | |
466 | |
467 // The border object is owned by this object and may be NULL. | |
468 void set_border(Border* b) { border_.reset(b); } | |
469 const Border* border() const { return border_.get(); } | |
470 Border* border() { return border_.get(); } | |
471 | |
472 // Get the theme provider from the parent widget. | |
473 virtual ui::ThemeProvider* GetThemeProvider() const; | |
474 | |
475 // RTL painting -------------------------------------------------------------- | |
476 | |
477 // This method determines whether the gfx::Canvas object passed to | |
478 // View::Paint() needs to be transformed such that anything drawn on the | |
479 // canvas object during View::Paint() is flipped horizontally. | |
480 // | |
481 // By default, this function returns false (which is the initial value of | |
482 // |flip_canvas_on_paint_for_rtl_ui_|). View subclasses that need to paint on | |
483 // a flipped gfx::Canvas when the UI layout is right-to-left need to call | |
484 // EnableCanvasFlippingForRTLUI(). | |
485 bool FlipCanvasOnPaintForRTLUI() const { | |
486 return flip_canvas_on_paint_for_rtl_ui_ ? base::i18n::IsRTL() : false; | |
487 } | |
488 | |
489 // Enables or disables flipping of the gfx::Canvas during View::Paint(). | |
490 // Note that if canvas flipping is enabled, the canvas will be flipped only | |
491 // if the UI layout is right-to-left; that is, the canvas will be flipped | |
492 // only if base::i18n::IsRTL() returns true. | |
493 // | |
494 // Enabling canvas flipping is useful for leaf views that draw a bitmap that | |
495 // needs to be flipped horizontally when the UI layout is right-to-left | |
496 // (views::Button, for example). This method is helpful for such classes | |
497 // because their drawing logic stays the same and they can become agnostic to | |
498 // the UI directionality. | |
499 void EnableCanvasFlippingForRTLUI(bool enable) { | |
500 flip_canvas_on_paint_for_rtl_ui_ = enable; | |
501 } | |
502 | |
503 // Accelerated painting ------------------------------------------------------ | |
504 | |
505 // Enable/Disable accelerated compositing. | |
506 static void set_use_acceleration_when_possible(bool use); | |
507 static bool get_use_acceleration_when_possible(); | |
508 | |
509 // Input --------------------------------------------------------------------- | |
510 // The points (and mouse locations) in the following functions are in the | |
511 // view's coordinates, except for a RootView. | |
512 | |
513 // Returns the deepest visible descendant that contains the specified point. | |
514 virtual View* GetEventHandlerForPoint(const gfx::Point& point); | |
515 | |
516 // Return the cursor that should be used for this view or the default cursor. | |
517 // The event location is in the receiver's coordinate system. The caller is | |
518 // responsible for managing the lifetime of the returned object, though that | |
519 // lifetime may vary from platform to platform. On Windows, the cursor is a | |
520 // shared resource, but Gtk destroys the returned cursor after setting it. | |
521 virtual gfx::NativeCursor GetCursor(const MouseEvent& event); | |
522 | |
523 // Convenience to test whether a point is within this view's bounds | |
524 virtual bool HitTest(const gfx::Point& l) const; | |
525 | |
526 // This method is invoked when the user clicks on this view. | |
527 // The provided event is in the receiver's coordinate system. | |
528 // | |
529 // Return true if you processed the event and want to receive subsequent | |
530 // MouseDraggged and MouseReleased events. This also stops the event from | |
531 // bubbling. If you return false, the event will bubble through parent | |
532 // views. | |
533 // | |
534 // If you remove yourself from the tree while processing this, event bubbling | |
535 // stops as if you returned true, but you will not receive future events. | |
536 // The return value is ignored in this case. | |
537 // | |
538 // Default implementation returns true if a ContextMenuController has been | |
539 // set, false otherwise. Override as needed. | |
540 // | |
541 virtual bool OnMousePressed(const MouseEvent& event); | |
542 | |
543 // This method is invoked when the user clicked on this control. | |
544 // and is still moving the mouse with a button pressed. | |
545 // The provided event is in the receiver's coordinate system. | |
546 // | |
547 // Return true if you processed the event and want to receive | |
548 // subsequent MouseDragged and MouseReleased events. | |
549 // | |
550 // Default implementation returns true if a ContextMenuController has been | |
551 // set, false otherwise. Override as needed. | |
552 // | |
553 virtual bool OnMouseDragged(const MouseEvent& event); | |
554 | |
555 // This method is invoked when the user releases the mouse | |
556 // button. The event is in the receiver's coordinate system. | |
557 // | |
558 // Default implementation notifies the ContextMenuController is appropriate. | |
559 // Subclasses that wish to honor the ContextMenuController should invoke | |
560 // super. | |
561 virtual void OnMouseReleased(const MouseEvent& event); | |
562 | |
563 // This method is invoked when the mouse press/drag was canceled by a | |
564 // system/user gesture. | |
565 virtual void OnMouseCaptureLost(); | |
566 | |
567 // This method is invoked when the mouse is above this control | |
568 // The event is in the receiver's coordinate system. | |
569 // | |
570 // Default implementation does nothing. Override as needed. | |
571 virtual void OnMouseMoved(const MouseEvent& event); | |
572 | |
573 // This method is invoked when the mouse enters this control. | |
574 // | |
575 // Default implementation does nothing. Override as needed. | |
576 virtual void OnMouseEntered(const MouseEvent& event); | |
577 | |
578 // This method is invoked when the mouse exits this control | |
579 // The provided event location is always (0, 0) | |
580 // Default implementation does nothing. Override as needed. | |
581 virtual void OnMouseExited(const MouseEvent& event); | |
582 | |
583 // This method is invoked for each touch event. Default implementation | |
584 // does nothing. Override as needed. | |
585 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event); | |
586 | |
587 // Set the MouseHandler for a drag session. | |
588 // | |
589 // A drag session is a stream of mouse events starting | |
590 // with a MousePressed event, followed by several MouseDragged | |
591 // events and finishing with a MouseReleased event. | |
592 // | |
593 // This method should be only invoked while processing a | |
594 // MouseDragged or MousePressed event. | |
595 // | |
596 // All further mouse dragged and mouse up events will be sent | |
597 // the MouseHandler, even if it is reparented to another window. | |
598 // | |
599 // The MouseHandler is automatically cleared when the control | |
600 // comes back from processing the MouseReleased event. | |
601 // | |
602 // Note: if the mouse handler is no longer connected to a | |
603 // view hierarchy, events won't be sent. | |
604 // | |
605 virtual void SetMouseHandler(View* new_mouse_handler); | |
606 | |
607 // Invoked when a key is pressed or released. | |
608 // Subclasser should return true if the event has been processed and false | |
609 // otherwise. If the event has not been processed, the parent will be given a | |
610 // chance. | |
611 virtual bool OnKeyPressed(const KeyEvent& event); | |
612 virtual bool OnKeyReleased(const KeyEvent& event); | |
613 | |
614 // Invoked when the user uses the mousewheel. Implementors should return true | |
615 // if the event has been processed and false otherwise. This message is sent | |
616 // if the view is focused. If the event has not been processed, the parent | |
617 // will be given a chance. | |
618 virtual bool OnMouseWheel(const MouseWheelEvent& event); | |
619 | |
620 // Returns the View's TextInputClient instance or NULL if the View doesn't | |
621 // support text input. | |
622 virtual ui::TextInputClient* GetTextInputClient(); | |
623 | |
624 // Convenience method to retrieve the InputMethod associated with the | |
625 // Widget that contains this view. Returns NULL if this view is not part of a | |
626 // view hierarchy with a Widget. | |
627 virtual InputMethod* GetInputMethod(); | |
628 | |
629 // Accelerators -------------------------------------------------------------- | |
630 | |
631 // Sets a keyboard accelerator for that view. When the user presses the | |
632 // accelerator key combination, the AcceleratorPressed method is invoked. | |
633 // Note that you can set multiple accelerators for a view by invoking this | |
634 // method several times. | |
635 virtual void AddAccelerator(const ui::Accelerator& accelerator); | |
636 | |
637 // Removes the specified accelerator for this view. | |
638 virtual void RemoveAccelerator(const ui::Accelerator& accelerator); | |
639 | |
640 // Removes all the keyboard accelerators for this view. | |
641 virtual void ResetAccelerators(); | |
642 | |
643 // Overridden from AcceleratorTarget: | |
644 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | |
645 | |
646 // Focus --------------------------------------------------------------------- | |
647 | |
648 // Returns whether this view currently has the focus. | |
649 virtual bool HasFocus() const; | |
650 | |
651 // Returns the view that should be selected next when pressing Tab. | |
652 View* GetNextFocusableView(); | |
653 const View* GetNextFocusableView() const; | |
654 | |
655 // Returns the view that should be selected next when pressing Shift-Tab. | |
656 View* GetPreviousFocusableView(); | |
657 | |
658 // Sets the component that should be selected next when pressing Tab, and | |
659 // makes the current view the precedent view of the specified one. | |
660 // Note that by default views are linked in the order they have been added to | |
661 // their container. Use this method if you want to modify the order. | |
662 // IMPORTANT NOTE: loops in the focus hierarchy are not supported. | |
663 void SetNextFocusableView(View* view); | |
664 | |
665 // Sets whether this view can accept the focus. | |
666 // Note that this is false by default so that a view used as a container does | |
667 // not get the focus. | |
668 void set_focusable(bool focusable) { focusable_ = focusable; } | |
669 | |
670 // Returns true if the view is focusable (IsFocusable) and visible in the root | |
671 // view. See also IsFocusable. | |
672 bool IsFocusableInRootView() const; | |
673 | |
674 // Return whether this view is focusable when the user requires full keyboard | |
675 // access, even though it may not be normally focusable. | |
676 bool IsAccessibilityFocusableInRootView() const; | |
677 | |
678 // Set whether this view can be made focusable if the user requires | |
679 // full keyboard access, even though it's not normally focusable. | |
680 // Note that this is false by default. | |
681 void set_accessibility_focusable(bool accessibility_focusable) { | |
682 accessibility_focusable_ = accessibility_focusable; | |
683 } | |
684 | |
685 // Convenience method to retrieve the FocusManager associated with the | |
686 // Widget that contains this view. This can return NULL if this view is not | |
687 // part of a view hierarchy with a Widget. | |
688 virtual FocusManager* GetFocusManager(); | |
689 virtual const FocusManager* GetFocusManager() const; | |
690 | |
691 // Request the keyboard focus. The receiving view will become the | |
692 // focused view. | |
693 virtual void RequestFocus(); | |
694 | |
695 // Invoked when a view is about to be requested for focus due to the focus | |
696 // traversal. Reverse is this request was generated going backward | |
697 // (Shift-Tab). | |
698 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) { } | |
699 | |
700 // Invoked when a key is pressed before the key event is processed (and | |
701 // potentially eaten) by the focus manager for tab traversal, accelerators and | |
702 // other focus related actions. | |
703 // The default implementation returns false, ensuring that tab traversal and | |
704 // accelerators processing is performed. | |
705 // Subclasses should return true if they want to process the key event and not | |
706 // have it processed as an accelerator (if any) or as a tab traversal (if the | |
707 // key event is for the TAB key). In that case, OnKeyPressed will | |
708 // subsequently be invoked for that event. | |
709 virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& event); | |
710 | |
711 // Subclasses that contain traversable children that are not directly | |
712 // accessible through the children hierarchy should return the associated | |
713 // FocusTraversable for the focus traversal to work properly. | |
714 virtual FocusTraversable* GetFocusTraversable(); | |
715 | |
716 // Subclasses that can act as a "pane" must implement their own | |
717 // FocusTraversable to keep the focus trapped within the pane. | |
718 // If this method returns an object, any view that's a direct or | |
719 // indirect child of this view will always use this FocusTraversable | |
720 // rather than the one from the widget. | |
721 virtual FocusTraversable* GetPaneFocusTraversable(); | |
722 | |
723 // Tooltips ------------------------------------------------------------------ | |
724 | |
725 // Gets the tooltip for this View. If the View does not have a tooltip, | |
726 // return false. If the View does have a tooltip, copy the tooltip into | |
727 // the supplied string and return true. | |
728 // Any time the tooltip text that a View is displaying changes, it must | |
729 // invoke TooltipTextChanged. | |
730 // |p| provides the coordinates of the mouse (relative to this view). | |
731 virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) const; | |
732 | |
733 // Returns the location (relative to this View) for the text on the tooltip | |
734 // to display. If false is returned (the default), the tooltip is placed at | |
735 // a default position. | |
736 virtual bool GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* loc) const; | |
737 | |
738 // Context menus ------------------------------------------------------------- | |
739 | |
740 // Sets the ContextMenuController. Setting this to non-null makes the View | |
741 // process mouse events. | |
742 ContextMenuController* context_menu_controller() { | |
743 return context_menu_controller_; | |
744 } | |
745 void set_context_menu_controller(ContextMenuController* menu_controller) { | |
746 context_menu_controller_ = menu_controller; | |
747 } | |
748 | |
749 // Provides default implementation for context menu handling. The default | |
750 // implementation calls the ShowContextMenu of the current | |
751 // ContextMenuController (if it is not NULL). Overridden in subclassed views | |
752 // to provide right-click menu display triggerd by the keyboard (i.e. for the | |
753 // Chrome toolbar Back and Forward buttons). No source needs to be specified, | |
754 // as it is always equal to the current View. | |
755 virtual void ShowContextMenu(const gfx::Point& p, | |
756 bool is_mouse_gesture); | |
757 | |
758 // Drag and drop ------------------------------------------------------------- | |
759 | |
760 DragController* drag_controller() { return drag_controller_; } | |
761 void set_drag_controller(DragController* drag_controller) { | |
762 drag_controller_ = drag_controller; | |
763 } | |
764 | |
765 // During a drag and drop session when the mouse moves the view under the | |
766 // mouse is queried for the drop types it supports by way of the | |
767 // GetDropFormats methods. If the view returns true and the drag site can | |
768 // provide data in one of the formats, the view is asked if the drop data | |
769 // is required before any other drop events are sent. Once the | |
770 // data is available the view is asked if it supports the drop (by way of | |
771 // the CanDrop method). If a view returns true from CanDrop, | |
772 // OnDragEntered is sent to the view when the mouse first enters the view, | |
773 // as the mouse moves around within the view OnDragUpdated is invoked. | |
774 // If the user releases the mouse over the view and OnDragUpdated returns a | |
775 // valid drop, then OnPerformDrop is invoked. If the mouse moves outside the | |
776 // view or over another view that wants the drag, OnDragExited is invoked. | |
777 // | |
778 // Similar to mouse events, the deepest view under the mouse is first checked | |
779 // if it supports the drop (Drop). If the deepest view under | |
780 // the mouse does not support the drop, the ancestors are walked until one | |
781 // is found that supports the drop. | |
782 | |
783 // Override and return the set of formats that can be dropped on this view. | |
784 // |formats| is a bitmask of the formats defined bye OSExchangeData::Format. | |
785 // The default implementation returns false, which means the view doesn't | |
786 // support dropping. | |
787 virtual bool GetDropFormats( | |
788 int* formats, | |
789 std::set<OSExchangeData::CustomFormat>* custom_formats); | |
790 | |
791 // Override and return true if the data must be available before any drop | |
792 // methods should be invoked. The default is false. | |
793 virtual bool AreDropTypesRequired(); | |
794 | |
795 // A view that supports drag and drop must override this and return true if | |
796 // data contains a type that may be dropped on this view. | |
797 virtual bool CanDrop(const OSExchangeData& data); | |
798 | |
799 // OnDragEntered is invoked when the mouse enters this view during a drag and | |
800 // drop session and CanDrop returns true. This is immediately | |
801 // followed by an invocation of OnDragUpdated, and eventually one of | |
802 // OnDragExited or OnPerformDrop. | |
803 virtual void OnDragEntered(const DropTargetEvent& event); | |
804 | |
805 // Invoked during a drag and drop session while the mouse is over the view. | |
806 // This should return a bitmask of the DragDropTypes::DragOperation supported | |
807 // based on the location of the event. Return 0 to indicate the drop should | |
808 // not be accepted. | |
809 virtual int OnDragUpdated(const DropTargetEvent& event); | |
810 | |
811 // Invoked during a drag and drop session when the mouse exits the views, or | |
812 // when the drag session was canceled and the mouse was over the view. | |
813 virtual void OnDragExited(); | |
814 | |
815 // Invoked during a drag and drop session when OnDragUpdated returns a valid | |
816 // operation and the user release the mouse. | |
817 virtual int OnPerformDrop(const DropTargetEvent& event); | |
818 | |
819 // Invoked from DoDrag after the drag completes. This implementation does | |
820 // nothing, and is intended for subclasses to do cleanup. | |
821 virtual void OnDragDone(); | |
822 | |
823 // Returns true if the mouse was dragged enough to start a drag operation. | |
824 // delta_x and y are the distance the mouse was dragged. | |
825 static bool ExceededDragThreshold(int delta_x, int delta_y); | |
826 | |
827 // Accessibility ------------------------------------------------------------- | |
828 | |
829 // Modifies |state| to reflect the current accessible state of this view. | |
830 virtual void GetAccessibleState(ui::AccessibleViewState* state) { } | |
831 | |
832 // Returns an instance of the native accessibility interface for this view. | |
833 virtual gfx::NativeViewAccessible GetNativeViewAccessible(); | |
834 | |
835 // Scrolling ----------------------------------------------------------------- | |
836 // TODO(beng): Figure out if this can live somewhere other than View, i.e. | |
837 // closer to ScrollView. | |
838 | |
839 // Scrolls the specified region, in this View's coordinate system, to be | |
840 // visible. View's implementation passes the call onto the parent View (after | |
841 // adjusting the coordinates). It is up to views that only show a portion of | |
842 // the child view, such as Viewport, to override appropriately. | |
843 virtual void ScrollRectToVisible(const gfx::Rect& rect); | |
844 | |
845 // The following methods are used by ScrollView to determine the amount | |
846 // to scroll relative to the visible bounds of the view. For example, a | |
847 // return value of 10 indicates the scrollview should scroll 10 pixels in | |
848 // the appropriate direction. | |
849 // | |
850 // Each method takes the following parameters: | |
851 // | |
852 // is_horizontal: if true, scrolling is along the horizontal axis, otherwise | |
853 // the vertical axis. | |
854 // is_positive: if true, scrolling is by a positive amount. Along the | |
855 // vertical axis scrolling by a positive amount equates to | |
856 // scrolling down. | |
857 // | |
858 // The return value should always be positive and gives the number of pixels | |
859 // to scroll. ScrollView interprets a return value of 0 (or negative) | |
860 // to scroll by a default amount. | |
861 // | |
862 // See VariableRowHeightScrollHelper and FixedRowHeightScrollHelper for | |
863 // implementations of common cases. | |
864 virtual int GetPageScrollIncrement(ScrollView* scroll_view, | |
865 bool is_horizontal, bool is_positive); | |
866 virtual int GetLineScrollIncrement(ScrollView* scroll_view, | |
867 bool is_horizontal, bool is_positive); | |
868 | |
869 protected: | |
870 // Size and disposition ------------------------------------------------------ | |
871 | |
872 // Override to be notified when the bounds of the view have changed. | |
873 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds); | |
874 | |
875 // Called when the preferred size of a child view changed. This gives the | |
876 // parent an opportunity to do a fresh layout if that makes sense. | |
877 virtual void ChildPreferredSizeChanged(View* child) {} | |
878 | |
879 // Invalidates the layout and calls ChildPreferredSizeChanged on the parent | |
880 // if there is one. Be sure to call View::PreferredSizeChanged when | |
881 // overriding such that the layout is properly invalidated. | |
882 virtual void PreferredSizeChanged(); | |
883 | |
884 // Override returning true when the view needs to be notified when its visible | |
885 // bounds relative to the root view may have changed. Only used by | |
886 // NativeViewHost. | |
887 virtual bool NeedsNotificationWhenVisibleBoundsChange() const; | |
888 | |
889 // Notification that this View's visible bounds relative to the root view may | |
890 // have changed. The visible bounds are the region of the View not clipped by | |
891 // its ancestors. This is used for clipping NativeViewHost. | |
892 virtual void OnVisibleBoundsChanged(); | |
893 | |
894 // Override to be notified when the enabled state of this View has | |
895 // changed. The default implementation calls SchedulePaint() on this View. | |
896 virtual void OnEnabledChanged(); | |
897 | |
898 // Tree operations ----------------------------------------------------------- | |
899 | |
900 // This method is invoked when the tree changes. | |
901 // | |
902 // When a view is removed, it is invoked for all children and grand | |
903 // children. For each of these views, a notification is sent to the | |
904 // view and all parents. | |
905 // | |
906 // When a view is added, a notification is sent to the view, all its | |
907 // parents, and all its children (and grand children) | |
908 // | |
909 // Default implementation does nothing. Override to perform operations | |
910 // required when a view is added or removed from a view hierarchy | |
911 // | |
912 // parent is the new or old parent. Child is the view being added or | |
913 // removed. | |
914 // | |
915 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); | |
916 | |
917 // When SetVisible() changes the visibility of a view, this method is | |
918 // invoked for that view as well as all the children recursively. | |
919 virtual void VisibilityChanged(View* starting_from, bool is_visible); | |
920 | |
921 // Called when the native view hierarchy changed. | |
922 // |attached| is true if that view has been attached to a new NativeView | |
923 // hierarchy, false if it has been detached. | |
924 // |native_view| is the NativeView this view was attached/detached from, and | |
925 // |root_view| is the root view associated with the NativeView. | |
926 // Views created without a native view parent don't have a focus manager. | |
927 // When this function is called they could do the processing that requires | |
928 // it - like registering accelerators, for example. | |
929 virtual void NativeViewHierarchyChanged(bool attached, | |
930 gfx::NativeView native_view, | |
931 internal::RootView* root_view); | |
932 | |
933 // Painting ------------------------------------------------------------------ | |
934 | |
935 // Responsible for calling Paint() on child Views. Override to control the | |
936 // order child Views are painted. | |
937 virtual void PaintChildren(gfx::Canvas* canvas); | |
938 | |
939 // Override to provide rendering in any part of the View's bounds. Typically | |
940 // this is the "contents" of the view. If you override this method you will | |
941 // have to call the subsequent OnPaint*() methods manually. | |
942 virtual void OnPaint(gfx::Canvas* canvas); | |
943 | |
944 // Override to paint a background before any content is drawn. Typically this | |
945 // is done if you are satisfied with a default OnPaint handler but wish to | |
946 // supply a different background. | |
947 virtual void OnPaintBackground(gfx::Canvas* canvas); | |
948 | |
949 // Override to paint a border not specified by SetBorder(). | |
950 virtual void OnPaintBorder(gfx::Canvas* canvas); | |
951 | |
952 // Override to paint a focus border (usually a dotted rectangle) around | |
953 // relevant contents. | |
954 virtual void OnPaintFocusBorder(gfx::Canvas* canvas); | |
955 | |
956 // Accelerated painting ------------------------------------------------------ | |
957 | |
958 // This creates a layer for the view, if one does not exist. It then | |
959 // passes the texture to a layer associated with the view. While an external | |
960 // texture is set, the view will not update the layer contents. | |
961 // | |
962 // |texture| cannot be NULL. | |
963 // | |
964 // Returns false if it cannot create a layer to which to assign the texture. | |
965 bool SetExternalTexture(ui::Texture* texture); | |
966 | |
967 // Returns the offset from this view to the nearest ancestor with a layer. | |
968 // If |ancestor| is non-NULL it is set to the nearest ancestor with a layer. | |
969 virtual void CalculateOffsetToAncestorWithLayer( | |
970 gfx::Point* offset, | |
971 ui::Layer** layer_parent); | |
972 | |
973 // If this view has a layer, the layer is reparented to |parent_layer| and its | |
974 // bounds is set based on |point|. If this view does not have a layer, then | |
975 // recurses through all children. This is used when adding a layer to an | |
976 // existing view to make sure all descendants that have layers are parented to | |
977 // the right layer. | |
978 virtual void MoveLayerToParent(ui::Layer* parent_layer, | |
979 const gfx::Point& point); | |
980 | |
981 // Called to update the bounds of any child layers within this View's | |
982 // hierarchy when something happens to the hierarchy. | |
983 virtual void UpdateChildLayerBounds(const gfx::Point& offset); | |
984 | |
985 // Overridden from ui::LayerDelegate: | |
986 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE; | |
987 | |
988 // Finds the layer that this view paints to (it may belong to an ancestor | |
989 // view), then reorders the immediate children of that layer to match the | |
990 // order of the view tree. | |
991 virtual void ReorderLayers(); | |
992 | |
993 // This reorders the immediate children of |*parent_layer| to match the | |
994 // order of the view tree. | |
995 virtual void ReorderChildLayers(ui::Layer* parent_layer); | |
996 | |
997 // Input --------------------------------------------------------------------- | |
998 | |
999 // Called by HitTest to see if this View has a custom hit test mask. If the | |
1000 // return value is true, GetHitTestMask will be called to obtain the mask. | |
1001 // Default value is false, in which case the View will hit-test against its | |
1002 // bounds. | |
1003 virtual bool HasHitTestMask() const; | |
1004 | |
1005 // Called by HitTest to retrieve a mask for hit-testing against. Subclasses | |
1006 // override to provide custom shaped hit test regions. | |
1007 virtual void GetHitTestMask(gfx::Path* mask) const; | |
1008 | |
1009 // Focus --------------------------------------------------------------------- | |
1010 | |
1011 // Returns whether this view can accept focus. | |
1012 // A view can accept focus if it's enabled, focusable and visible. | |
1013 // This method is intended for views to use when calculating preferred size. | |
1014 // The FocusManager and other places use IsFocusableInRootView. | |
1015 virtual bool IsFocusable() const; | |
1016 | |
1017 // Override to be notified when focus has changed either to or from this View. | |
1018 virtual void OnFocus(); | |
1019 virtual void OnBlur(); | |
1020 | |
1021 // Handle view focus/blur events for this view. | |
1022 void Focus(); | |
1023 void Blur(); | |
1024 | |
1025 // System events ------------------------------------------------------------- | |
1026 | |
1027 // Called when the UI theme has changed, overriding allows individual Views to | |
1028 // do special cleanup and processing (such as dropping resource caches). | |
1029 // To dispatch a theme changed notification, call Widget::ThemeChanged(). | |
1030 virtual void OnThemeChanged() {} | |
1031 | |
1032 // Called when the locale has changed, overriding allows individual Views to | |
1033 // update locale-dependent strings. | |
1034 // To dispatch a locale changed notification, call Widget::LocaleChanged(). | |
1035 virtual void OnLocaleChanged() {} | |
1036 | |
1037 // Tooltips ------------------------------------------------------------------ | |
1038 | |
1039 // Views must invoke this when the tooltip text they are to display changes. | |
1040 void TooltipTextChanged(); | |
1041 | |
1042 // Context menus ------------------------------------------------------------- | |
1043 | |
1044 // Returns the location, in screen coordinates, to show the context menu at | |
1045 // when the context menu is shown from the keyboard. This implementation | |
1046 // returns the middle of the visible region of this view. | |
1047 // | |
1048 // This method is invoked when the context menu is shown by way of the | |
1049 // keyboard. | |
1050 virtual gfx::Point GetKeyboardContextMenuLocation(); | |
1051 | |
1052 // Drag and drop ------------------------------------------------------------- | |
1053 | |
1054 // These are cover methods that invoke the method of the same name on | |
1055 // the DragController. Subclasses may wish to override rather than install | |
1056 // a DragController. | |
1057 // See DragController for a description of these methods. | |
1058 virtual int GetDragOperations(const gfx::Point& press_pt); | |
1059 virtual void WriteDragData(const gfx::Point& press_pt, OSExchangeData* data); | |
1060 | |
1061 // Returns whether we're in the middle of a drag session that was initiated | |
1062 // by us. | |
1063 bool InDrag(); | |
1064 | |
1065 // Returns how much the mouse needs to move in one direction to start a | |
1066 // drag. These methods cache in a platform-appropriate way. These values are | |
1067 // used by the public static method ExceededDragThreshold(). | |
1068 static int GetHorizontalDragThreshold(); | |
1069 static int GetVerticalDragThreshold(); | |
1070 | |
1071 // Debugging ----------------------------------------------------------------- | |
1072 | |
1073 #if !defined(NDEBUG) | |
1074 // Returns string containing a graph of the views hierarchy in graphViz DOT | |
1075 // language (http://graphviz.org/). Can be called within debugger and save | |
1076 // to a file to compile/view. | |
1077 // Note: Assumes initial call made with first = true. | |
1078 virtual std::string PrintViewGraph(bool first); | |
1079 | |
1080 // Some classes may own an object which contains the children to displayed in | |
1081 // the views hierarchy. The above function gives the class the flexibility to | |
1082 // decide which object should be used to obtain the children, but this | |
1083 // function makes the decision explicit. | |
1084 std::string DoPrintViewGraph(bool first, View* view_with_children); | |
1085 #endif | |
1086 | |
1087 private: | |
1088 friend class internal::NativeWidgetView; | |
1089 friend class internal::RootView; | |
1090 friend class FocusManager; | |
1091 friend class ViewStorage; | |
1092 friend class Widget; | |
1093 friend class PaintLock; | |
1094 | |
1095 // Used to track a drag. RootView passes this into | |
1096 // ProcessMousePressed/Dragged. | |
1097 struct DragInfo { | |
1098 // Sets possible_drag to false and start_x/y to 0. This is invoked by | |
1099 // RootView prior to invoke ProcessMousePressed. | |
1100 void Reset(); | |
1101 | |
1102 // Sets possible_drag to true and start_pt to the specified point. | |
1103 // This is invoked by the target view if it detects the press may generate | |
1104 // a drag. | |
1105 void PossibleDrag(const gfx::Point& p); | |
1106 | |
1107 // Whether the press may generate a drag. | |
1108 bool possible_drag; | |
1109 | |
1110 // Coordinates of the mouse press. | |
1111 gfx::Point start_pt; | |
1112 }; | |
1113 | |
1114 // Painting ----------------------------------------------------------------- | |
1115 | |
1116 enum SchedulePaintType { | |
1117 // Indicates the size is the same (only the origin changed). | |
1118 SCHEDULE_PAINT_SIZE_SAME, | |
1119 | |
1120 // Indicates the size changed (and possibly the origin). | |
1121 SCHEDULE_PAINT_SIZE_CHANGED | |
1122 }; | |
1123 | |
1124 // Invoked before and after the bounds change to schedule painting the old and | |
1125 // new bounds. | |
1126 void SchedulePaintBoundsChanged(SchedulePaintType type); | |
1127 | |
1128 // Common Paint() code shared by accelerated and non-accelerated code paths to | |
1129 // invoke OnPaint() on the View. | |
1130 void PaintCommon(gfx::Canvas* canvas); | |
1131 | |
1132 // Tree operations ----------------------------------------------------------- | |
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 // Call ViewHierarchyChanged for all child views on all parents | |
1145 void PropagateRemoveNotifications(View* parent); | |
1146 | |
1147 // Call ViewHierarchyChanged for all children | |
1148 void PropagateAddNotifications(View* parent, View* child); | |
1149 | |
1150 // Propagates NativeViewHierarchyChanged() notification through all the | |
1151 // children. | |
1152 void PropagateNativeViewHierarchyChanged(bool attached, | |
1153 gfx::NativeView native_view, | |
1154 internal::RootView* root_view); | |
1155 | |
1156 // Takes care of registering/unregistering accelerators if | |
1157 // |register_accelerators| true and calls ViewHierarchyChanged(). | |
1158 void ViewHierarchyChangedImpl(bool register_accelerators, | |
1159 bool is_add, | |
1160 View* parent, | |
1161 View* child); | |
1162 | |
1163 // Size and disposition ------------------------------------------------------ | |
1164 | |
1165 // Call VisibilityChanged() recursively for all children. | |
1166 void PropagateVisibilityNotifications(View* from, bool is_visible); | |
1167 | |
1168 // Registers/unregisters accelerators as necessary and calls | |
1169 // VisibilityChanged(). | |
1170 void VisibilityChangedImpl(View* starting_from, bool is_visible); | |
1171 | |
1172 // Responsible for propagating bounds change notifications to relevant | |
1173 // views. | |
1174 void BoundsChanged(const gfx::Rect& previous_bounds); | |
1175 | |
1176 // Visible bounds notification registration. | |
1177 // When a view is added to a hierarchy, it and all its children are asked if | |
1178 // they need to be registered for "visible bounds within root" notifications | |
1179 // (see comment on OnVisibleBoundsChanged()). If they do, they are registered | |
1180 // with every ancestor between them and the root of the hierarchy. | |
1181 static void RegisterChildrenForVisibleBoundsNotification(View* view); | |
1182 static void UnregisterChildrenForVisibleBoundsNotification(View* view); | |
1183 void RegisterForVisibleBoundsNotification(); | |
1184 void UnregisterForVisibleBoundsNotification(); | |
1185 | |
1186 // Adds/removes view to the list of descendants that are notified any time | |
1187 // this views location and possibly size are changed. | |
1188 void AddDescendantToNotify(View* view); | |
1189 void RemoveDescendantToNotify(View* view); | |
1190 | |
1191 // Transformations ----------------------------------------------------------- | |
1192 | |
1193 // Returns in |transform| the transform to get from coordinates of |ancestor| | |
1194 // to this. Returns true if |ancestor| is found. If |ancestor| is not found, | |
1195 // or NULL, |transform| is set to convert from root view coordinates to this. | |
1196 bool GetTransformRelativeTo(const View* ancestor, | |
1197 ui::Transform* transform) const; | |
1198 | |
1199 // Coordinate conversion ----------------------------------------------------- | |
1200 | |
1201 // Convert a point in the view's coordinate to an ancestor view's coordinate | |
1202 // system using necessary transformations. Returns whether the point was | |
1203 // successfully converted to the ancestor's coordinate system. | |
1204 bool ConvertPointForAncestor(const View* ancestor, gfx::Point* point) const; | |
1205 | |
1206 // Convert a point in the ancestor's coordinate system to the view's | |
1207 // coordinate system using necessary transformations. Returns whether the | |
1208 // point was successfully from the ancestor's coordinate system to the view's | |
1209 // coordinate system. | |
1210 bool ConvertPointFromAncestor(const View* ancestor, gfx::Point* point) const; | |
1211 | |
1212 // Accelerated painting ------------------------------------------------------ | |
1213 | |
1214 // Disables painting during time critical operations. Used by PaintLock. | |
1215 // TODO(vollick) Ideally, the widget would not dispatch paints into the | |
1216 // hierarchy during time critical operations and this would not be needed. | |
1217 void set_painting_enabled(bool enabled) { painting_enabled_ = enabled; } | |
1218 | |
1219 // Creates the layer and related fields for this view. | |
1220 void CreateLayer(); | |
1221 | |
1222 // Parents all un-parented layers within this view's hierarchy to this view's | |
1223 // layer. | |
1224 void UpdateParentLayers(); | |
1225 | |
1226 // Updates the view's layer's parent. Called when a view is added to a view | |
1227 // hierarchy, responsible for parenting the view's layer to the enclosing | |
1228 // layer in the hierarchy. | |
1229 void UpdateParentLayer(); | |
1230 | |
1231 // Parents this view's layer to |parent_layer|, and sets its bounds and other | |
1232 // properties in accordance to |offset|, the view's offset from the | |
1233 // |parent_layer|. | |
1234 void ReparentLayer(const gfx::Point& offset, ui::Layer* parent_layer); | |
1235 | |
1236 // Called to update the layer visibility. The layer will be visible if the | |
1237 // View itself, and all its parent Views are visible. This also updates | |
1238 // visibility of the child layers. | |
1239 void UpdateLayerVisibility(); | |
1240 void UpdateChildLayerVisibility(bool visible); | |
1241 | |
1242 // Orphans the layers in this subtree that are parented to layers outside of | |
1243 // this subtree. | |
1244 void OrphanLayers(); | |
1245 | |
1246 // Destroys the layer associated with this view, and reparents any descendants | |
1247 // to the destroyed layer's parent. | |
1248 void DestroyLayer(); | |
1249 | |
1250 // Input --------------------------------------------------------------------- | |
1251 | |
1252 // RootView invokes these. These in turn invoke the appropriate OnMouseXXX | |
1253 // method. If a drag is detected, DoDrag is invoked. | |
1254 bool ProcessMousePressed(const MouseEvent& event, DragInfo* drop_info); | |
1255 bool ProcessMouseDragged(const MouseEvent& event, DragInfo* drop_info); | |
1256 void ProcessMouseReleased(const MouseEvent& event); | |
1257 | |
1258 // RootView will invoke this with incoming TouchEvents. Returns the | |
1259 // the result of OnTouchEvent. | |
1260 ui::TouchStatus ProcessTouchEvent(const TouchEvent& event); | |
1261 | |
1262 // Accelerators -------------------------------------------------------------- | |
1263 | |
1264 // Registers this view's keyboard accelerators that are not registered to | |
1265 // FocusManager yet, if possible. | |
1266 void RegisterPendingAccelerators(); | |
1267 | |
1268 // Unregisters all the keyboard accelerators associated with this view. | |
1269 // |leave_data_intact| if true does not remove data from accelerators_ array, | |
1270 // so it could be re-registered with other focus manager | |
1271 void UnregisterAccelerators(bool leave_data_intact); | |
1272 | |
1273 // Focus --------------------------------------------------------------------- | |
1274 | |
1275 // Initialize the previous/next focusable views of the specified view relative | |
1276 // to the view at the specified index. | |
1277 void InitFocusSiblings(View* view, int index); | |
1278 | |
1279 // System events ------------------------------------------------------------- | |
1280 | |
1281 // Used to propagate theme changed notifications from the root view to all | |
1282 // views in the hierarchy. | |
1283 virtual void PropagateThemeChanged(); | |
1284 | |
1285 // Used to propagate locale changed notifications from the root view to all | |
1286 // views in the hierarchy. | |
1287 virtual void PropagateLocaleChanged(); | |
1288 | |
1289 // Tooltips ------------------------------------------------------------------ | |
1290 | |
1291 // Propagates UpdateTooltip() to the TooltipManager for the Widget. | |
1292 // This must be invoked any time the View hierarchy changes in such a way | |
1293 // the view under the mouse differs. For example, if the bounds of a View is | |
1294 // changed, this is invoked. Similarly, as Views are added/removed, this | |
1295 // is invoked. | |
1296 void UpdateTooltip(); | |
1297 | |
1298 // Drag and drop ------------------------------------------------------------- | |
1299 | |
1300 // Starts a drag and drop operation originating from this view. This invokes | |
1301 // WriteDragData to write the data and GetDragOperations to determine the | |
1302 // supported drag operations. When done, OnDragDone is invoked. | |
1303 void DoDrag(const MouseEvent& event, const gfx::Point& press_pt); | |
1304 | |
1305 ////////////////////////////////////////////////////////////////////////////// | |
1306 | |
1307 // Creation and lifetime ----------------------------------------------------- | |
1308 | |
1309 // True if the hierarchy (i.e. the parent View) is responsible for deleting | |
1310 // this View. Default is true. | |
1311 bool parent_owned_; | |
1312 | |
1313 // Attributes ---------------------------------------------------------------- | |
1314 | |
1315 // The id of this View. Used to find this View. | |
1316 int id_; | |
1317 | |
1318 // The group of this view. Some view subclasses use this id to find other | |
1319 // views of the same group. For example radio button uses this information | |
1320 // to find other radio buttons. | |
1321 int group_; | |
1322 | |
1323 // Tree operations ----------------------------------------------------------- | |
1324 | |
1325 // This view's parent. | |
1326 View* parent_; | |
1327 | |
1328 // This view's children. | |
1329 Views children_; | |
1330 | |
1331 // Size and disposition ------------------------------------------------------ | |
1332 | |
1333 // This View's bounds in the parent coordinate system. | |
1334 gfx::Rect bounds_; | |
1335 | |
1336 // Whether this view is visible. | |
1337 bool visible_; | |
1338 | |
1339 // Whether this view is enabled. | |
1340 bool enabled_; | |
1341 | |
1342 // Whether this view is painting. | |
1343 bool painting_enabled_; | |
1344 | |
1345 // Whether or not RegisterViewForVisibleBoundsNotification on the RootView | |
1346 // has been invoked. | |
1347 bool registered_for_visible_bounds_notification_; | |
1348 | |
1349 // List of descendants wanting notification when their visible bounds change. | |
1350 scoped_ptr<Views> descendants_to_notify_; | |
1351 | |
1352 // Transformations ----------------------------------------------------------- | |
1353 | |
1354 // Clipping parameters. skia transformation matrix does not give us clipping. | |
1355 // So we do it ourselves. | |
1356 float clip_x_; | |
1357 float clip_y_; | |
1358 | |
1359 // Layout -------------------------------------------------------------------- | |
1360 | |
1361 // Whether the view needs to be laid out. | |
1362 bool needs_layout_; | |
1363 | |
1364 // The View's LayoutManager defines the sizing heuristics applied to child | |
1365 // Views. The default is absolute positioning according to bounds_. | |
1366 scoped_ptr<LayoutManager> layout_manager_; | |
1367 | |
1368 // Painting ------------------------------------------------------------------ | |
1369 | |
1370 // Background | |
1371 scoped_ptr<Background> background_; | |
1372 | |
1373 // Border. | |
1374 scoped_ptr<Border> border_; | |
1375 | |
1376 // RTL painting -------------------------------------------------------------- | |
1377 | |
1378 // Indicates whether or not the gfx::Canvas object passed to View::Paint() | |
1379 // is going to be flipped horizontally (using the appropriate transform) on | |
1380 // right-to-left locales for this View. | |
1381 bool flip_canvas_on_paint_for_rtl_ui_; | |
1382 | |
1383 // Accelerated painting ------------------------------------------------------ | |
1384 | |
1385 bool paint_to_layer_; | |
1386 scoped_ptr<ui::Layer> layer_; | |
1387 | |
1388 // Accelerators -------------------------------------------------------------- | |
1389 | |
1390 // true if when we were added to hierarchy we were without focus manager | |
1391 // attempt addition when ancestor chain changed. | |
1392 bool accelerator_registration_delayed_; | |
1393 | |
1394 // Focus manager accelerators registered on. | |
1395 FocusManager* accelerator_focus_manager_; | |
1396 | |
1397 // The list of accelerators. List elements in the range | |
1398 // [0, registered_accelerator_count_) are already registered to FocusManager, | |
1399 // and the rest are not yet. | |
1400 scoped_ptr<std::vector<ui::Accelerator> > accelerators_; | |
1401 size_t registered_accelerator_count_; | |
1402 | |
1403 // Focus --------------------------------------------------------------------- | |
1404 | |
1405 // Next view to be focused when the Tab key is pressed. | |
1406 View* next_focusable_view_; | |
1407 | |
1408 // Next view to be focused when the Shift-Tab key combination is pressed. | |
1409 View* previous_focusable_view_; | |
1410 | |
1411 // Whether this view can be focused. | |
1412 bool focusable_; | |
1413 | |
1414 // Whether this view is focusable if the user requires full keyboard access, | |
1415 // even though it may not be normally focusable. | |
1416 bool accessibility_focusable_; | |
1417 | |
1418 // Context menus ------------------------------------------------------------- | |
1419 | |
1420 // The menu controller. | |
1421 ContextMenuController* context_menu_controller_; | |
1422 | |
1423 // Drag and drop ------------------------------------------------------------- | |
1424 | |
1425 DragController* drag_controller_; | |
1426 | |
1427 // Accessibility ------------------------------------------------------------- | |
1428 | |
1429 // The Windows-specific accessibility implementation for this view. | |
1430 #if defined(OS_WIN) | |
1431 base::win::ScopedComPtr<NativeViewAccessibilityWin> | |
1432 native_view_accessibility_win_; | |
1433 #endif | |
1434 | |
1435 DISALLOW_COPY_AND_ASSIGN(View); | |
1436 }; | |
1437 | |
1438 } // namespace views | |
1439 | |
1440 #endif // VIEWS_VIEW_H_ | |
OLD | NEW |