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_WIDGET_ROOT_VIEW_H_ | |
6 #define VIEWS_WIDGET_ROOT_VIEW_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/memory/ref_counted.h" | |
12 #include "ui/views/focus/focus_manager.h" | |
13 #include "ui/views/focus/focus_search.h" | |
14 #include "views/view.h" | |
15 | |
16 namespace ui { | |
17 enum TouchStatus; | |
18 } | |
19 | |
20 namespace views { | |
21 | |
22 class Widget; | |
23 class GestureManager; | |
24 | |
25 // This is a views-internal API and should not be used externally. | |
26 // Widget exposes this object as a View*. | |
27 namespace internal { | |
28 | |
29 //////////////////////////////////////////////////////////////////////////////// | |
30 // RootView class | |
31 // | |
32 // The RootView is the root of a View hierarchy. A RootView is attached to a | |
33 // Widget. The Widget is responsible for receiving events from the host | |
34 // environment, converting them to views-compatible events and then forwarding | |
35 // them to the RootView for propagation into the View hierarchy. | |
36 // | |
37 // A RootView can have only one child, called its "Contents View" which is | |
38 // sized to fill the bounds of the RootView (and hence the client area of the | |
39 // Widget). Call SetContentsView() after the associated Widget has been | |
40 // initialized to attach the contents view to the RootView. | |
41 // TODO(beng): Enforce no other callers to AddChildView/tree functions by | |
42 // overriding those methods as private here. | |
43 // TODO(beng): Clean up API further, make Widget a friend. | |
44 // TODO(sky): We don't really want to export this class. | |
45 // | |
46 class VIEWS_EXPORT RootView : public View, public FocusTraversable { | |
47 public: | |
48 static const char kViewClassName[]; | |
49 | |
50 // Creation and lifetime ----------------------------------------------------- | |
51 explicit RootView(Widget* widget); | |
52 virtual ~RootView(); | |
53 | |
54 // Tree operations ----------------------------------------------------------- | |
55 | |
56 // Sets the "contents view" of the RootView. This is the single child view | |
57 // that is responsible for laying out the contents of the widget. | |
58 void SetContentsView(View* contents_view); | |
59 View* GetContentsView(); | |
60 | |
61 // Called when parent of the host changed. | |
62 void NotifyNativeViewHierarchyChanged(bool attached, | |
63 gfx::NativeView native_view); | |
64 | |
65 // Input --------------------------------------------------------------------- | |
66 | |
67 // Process a key event. Send the event to the focused view and up the focus | |
68 // path, and finally to the default keyboard handler, until someone consumes | |
69 // it. Returns whether anyone consumed the event. | |
70 bool OnKeyEvent(const KeyEvent& event); | |
71 | |
72 // Provided only for testing: | |
73 void SetGestureManagerForTesting(GestureManager* g) { gesture_manager_ = g; } | |
74 | |
75 // Focus --------------------------------------------------------------------- | |
76 | |
77 // Used to set the FocusTraversable parent after the view has been created | |
78 // (typically when the hierarchy changes and this RootView is added/removed). | |
79 virtual void SetFocusTraversableParent(FocusTraversable* focus_traversable); | |
80 | |
81 // Used to set the View parent after the view has been created. | |
82 virtual void SetFocusTraversableParentView(View* view); | |
83 | |
84 // System events ------------------------------------------------------------- | |
85 | |
86 // Public API for broadcasting theme change notifications to this View | |
87 // hierarchy. | |
88 void ThemeChanged(); | |
89 | |
90 // Public API for broadcasting locale change notifications to this View | |
91 // hierarchy. | |
92 void LocaleChanged(); | |
93 | |
94 // Overridden from FocusTraversable: | |
95 virtual FocusSearch* GetFocusSearch() OVERRIDE; | |
96 virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE; | |
97 virtual View* GetFocusTraversableParentView() OVERRIDE; | |
98 | |
99 // Overridden from View: | |
100 virtual const Widget* GetWidget() const OVERRIDE; | |
101 virtual Widget* GetWidget() OVERRIDE; | |
102 virtual bool IsVisibleInRootView() const OVERRIDE; | |
103 virtual std::string GetClassName() const OVERRIDE; | |
104 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; | |
105 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; | |
106 virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; | |
107 virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE; | |
108 virtual void OnMouseCaptureLost() OVERRIDE; | |
109 virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; | |
110 virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; | |
111 virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE; | |
112 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; | |
113 virtual void SetMouseHandler(View* new_mouse_handler) OVERRIDE; | |
114 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | |
115 | |
116 protected: | |
117 // Overridden from View: | |
118 virtual void ViewHierarchyChanged(bool is_add, View* parent, | |
119 View* child) OVERRIDE; | |
120 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
121 virtual void CalculateOffsetToAncestorWithLayer( | |
122 gfx::Point* offset, | |
123 ui::Layer** layer_parent) OVERRIDE; | |
124 | |
125 private: | |
126 friend class View; | |
127 friend class Widget; | |
128 | |
129 // Required so the GestureManager can call the Process* entry points | |
130 // with synthetic events as necessary. | |
131 friend class GestureManager; | |
132 | |
133 // Input --------------------------------------------------------------------- | |
134 | |
135 // Update the cursor given a mouse event. This is called by non mouse_move | |
136 // event handlers to honor the cursor desired by views located under the | |
137 // cursor during drag operations. The location of the mouse should be in the | |
138 // current coordinate system (i.e. any necessary transformation should be | |
139 // applied to the point prior to calling this). | |
140 void UpdateCursor(const MouseEvent& event); | |
141 | |
142 // Updates the last_mouse_* fields from e. The location of the mouse should be | |
143 // in the current coordinate system (i.e. any necessary transformation should | |
144 // be applied to the point prior to calling this). | |
145 void SetMouseLocationAndFlags(const MouseEvent& event); | |
146 | |
147 ////////////////////////////////////////////////////////////////////////////// | |
148 | |
149 // Tree operations ----------------------------------------------------------- | |
150 | |
151 // The host Widget | |
152 Widget* widget_; | |
153 | |
154 // Input --------------------------------------------------------------------- | |
155 | |
156 // The view currently handing down - drag - up | |
157 View* mouse_pressed_handler_; | |
158 | |
159 // The view currently handling enter / exit | |
160 View* mouse_move_handler_; | |
161 | |
162 // The last view to handle a mouse click, so that we can determine if | |
163 // a double-click lands on the same view as its single-click part. | |
164 View* last_click_handler_; | |
165 | |
166 // true if mouse_pressed_handler_ has been explicitly set | |
167 bool explicit_mouse_handler_; | |
168 | |
169 // Last position/flag of a mouse press/drag. Used if capture stops and we need | |
170 // to synthesize a release. | |
171 int last_mouse_event_flags_; | |
172 int last_mouse_event_x_; | |
173 int last_mouse_event_y_; | |
174 | |
175 // The gesture_manager_ for this. | |
176 GestureManager* gesture_manager_; | |
177 | |
178 // The view currently handling touch events. | |
179 View* touch_pressed_handler_; | |
180 | |
181 // Focus --------------------------------------------------------------------- | |
182 | |
183 // The focus search algorithm. | |
184 FocusSearch focus_search_; | |
185 | |
186 // Whether this root view belongs to the current active window. | |
187 // bool activated_; | |
188 | |
189 // The parent FocusTraversable, used for focus traversal. | |
190 FocusTraversable* focus_traversable_parent_; | |
191 | |
192 // The View that contains this RootView. This is used when we have RootView | |
193 // wrapped inside native components, and is used for the focus traversal. | |
194 View* focus_traversable_parent_view_; | |
195 | |
196 // Drag and drop ------------------------------------------------------------- | |
197 | |
198 // Tracks drag state for a view. | |
199 View::DragInfo drag_info; | |
200 | |
201 DISALLOW_IMPLICIT_CONSTRUCTORS(RootView); | |
202 }; | |
203 | |
204 } // namespace internal | |
205 } // namespace views | |
206 | |
207 #endif // VIEWS_WIDGET_ROOT_VIEW_H_ | |
OLD | NEW |