GN: Fix clean build of cloud_policy_proto_generated_compile_proto failing
[chromium-blink-merge.git] / ui / views / widget / root_view.h
blob3e7b5247ebc46067f5c96218011b0bed102a30ec
1 // Copyright (c) 2012 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.
5 #ifndef UI_VIEWS_WIDGET_ROOT_VIEW_H_
6 #define UI_VIEWS_WIDGET_ROOT_VIEW_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "ui/events/event_processor.h"
12 #include "ui/views/focus/focus_manager.h"
13 #include "ui/views/focus/focus_search.h"
14 #include "ui/views/view.h"
15 #include "ui/views/view_targeter_delegate.h"
17 namespace views {
19 namespace test {
20 class ViewTargeterTest;
21 class WidgetTest;
24 class RootViewTargeter;
25 class Widget;
27 // This is a views-internal API and should not be used externally.
28 // Widget exposes this object as a View*.
29 namespace internal {
30 class PreEventDispatchHandler;
32 ////////////////////////////////////////////////////////////////////////////////
33 // RootView class
35 // The RootView is the root of a View hierarchy. A RootView is attached to a
36 // Widget. The Widget is responsible for receiving events from the host
37 // environment, converting them to views-compatible events and then forwarding
38 // them to the RootView for propagation into the View hierarchy.
40 // A RootView can have only one child, called its "Contents View" which is
41 // sized to fill the bounds of the RootView (and hence the client area of the
42 // Widget). Call SetContentsView() after the associated Widget has been
43 // initialized to attach the contents view to the RootView.
44 // TODO(beng): Enforce no other callers to AddChildView/tree functions by
45 // overriding those methods as private here.
46 // TODO(beng): Clean up API further, make Widget a friend.
47 // TODO(sky): We don't really want to export this class.
49 class VIEWS_EXPORT RootView : public View,
50 public ViewTargeterDelegate,
51 public FocusTraversable,
52 public ui::EventProcessor {
53 public:
54 static const char kViewClassName[];
56 // Creation and lifetime -----------------------------------------------------
57 explicit RootView(Widget* widget);
58 ~RootView() override;
60 // Tree operations -----------------------------------------------------------
62 // Sets the "contents view" of the RootView. This is the single child view
63 // that is responsible for laying out the contents of the widget.
64 void SetContentsView(View* contents_view);
65 View* GetContentsView();
67 // Called when parent of the host changed.
68 void NotifyNativeViewHierarchyChanged();
70 // Focus ---------------------------------------------------------------------
72 // Used to set the FocusTraversable parent after the view has been created
73 // (typically when the hierarchy changes and this RootView is added/removed).
74 virtual void SetFocusTraversableParent(FocusTraversable* focus_traversable);
76 // Used to set the View parent after the view has been created.
77 virtual void SetFocusTraversableParentView(View* view);
79 // System events -------------------------------------------------------------
81 // Public API for broadcasting theme change notifications to this View
82 // hierarchy.
83 void ThemeChanged();
85 // Public API for broadcasting locale change notifications to this View
86 // hierarchy.
87 void LocaleChanged();
89 // Public API for broadcasting device scale factor change notifications to
90 // this View hierarchy.
91 void DeviceScaleFactorChanged(float device_scale_factor);
93 // Overridden from FocusTraversable:
94 FocusSearch* GetFocusSearch() override;
95 FocusTraversable* GetFocusTraversableParent() override;
96 View* GetFocusTraversableParentView() override;
98 // Overridden from ui::EventProcessor:
99 ui::EventTarget* GetRootTarget() override;
100 void OnEventProcessingStarted(ui::Event* event) override;
101 void OnEventProcessingFinished(ui::Event* event) override;
103 // Overridden from View:
104 const Widget* GetWidget() const override;
105 Widget* GetWidget() override;
106 bool IsDrawn() const override;
107 void Layout() override;
108 const char* GetClassName() const override;
109 void SchedulePaintInRect(const gfx::Rect& rect) override;
110 bool OnMousePressed(const ui::MouseEvent& event) override;
111 bool OnMouseDragged(const ui::MouseEvent& event) override;
112 void OnMouseReleased(const ui::MouseEvent& event) override;
113 void OnMouseCaptureLost() override;
114 void OnMouseMoved(const ui::MouseEvent& event) override;
115 void OnMouseExited(const ui::MouseEvent& event) override;
116 bool OnMouseWheel(const ui::MouseWheelEvent& event) override;
117 void SetMouseHandler(View* new_mouse_handler) override;
118 void GetAccessibleState(ui::AXViewState* state) override;
119 void UpdateParentLayer() override;
121 protected:
122 // Overridden from View:
123 void ViewHierarchyChanged(
124 const ViewHierarchyChangedDetails& details) override;
125 void VisibilityChanged(View* starting_from, bool is_visible) override;
126 void OnPaint(gfx::Canvas* canvas) override;
127 gfx::Vector2d CalculateOffsetToAncestorWithLayer(
128 ui::Layer** layer_parent) override;
129 View::DragInfo* GetDragInfo() override;
131 private:
132 friend class ::views::RootViewTargeter;
133 friend class ::views::View;
134 friend class ::views::Widget;
135 friend class ::views::test::ViewTargeterTest;
136 friend class ::views::test::WidgetTest;
138 // Input ---------------------------------------------------------------------
140 // Update the cursor given a mouse event. This is called by non mouse_move
141 // event handlers to honor the cursor desired by views located under the
142 // cursor during drag operations. The location of the mouse should be in the
143 // current coordinate system (i.e. any necessary transformation should be
144 // applied to the point prior to calling this).
145 void UpdateCursor(const ui::MouseEvent& event);
147 // Updates the last_mouse_* fields from e. The location of the mouse should be
148 // in the current coordinate system (i.e. any necessary transformation should
149 // be applied to the point prior to calling this).
150 void SetMouseLocationAndFlags(const ui::MouseEvent& event);
152 // |view| is the view receiving |event|. This function sends the event to all
153 // the Views up the hierarchy that has |notify_enter_exit_on_child_| flag
154 // turned on, but does not contain |sibling|.
155 ui::EventDispatchDetails NotifyEnterExitOfDescendant(
156 const ui::MouseEvent& event,
157 ui::EventType type,
158 View* view,
159 View* sibling) WARN_UNUSED_RESULT;
161 // Overridden from ui::EventDispatcherDelegate:
162 bool CanDispatchToTarget(ui::EventTarget* target) override;
163 ui::EventDispatchDetails PreDispatchEvent(ui::EventTarget* target,
164 ui::Event* event) override;
165 ui::EventDispatchDetails PostDispatchEvent(ui::EventTarget* target,
166 const ui::Event& event) override;
168 //////////////////////////////////////////////////////////////////////////////
169 // Tree operations -----------------------------------------------------------
171 // The host Widget
172 Widget* widget_;
174 // Input ---------------------------------------------------------------------
176 // TODO(tdanderson): Consider moving the input-related members into
177 // ViewTargeter / RootViewTargeter.
179 // The view currently handing down - drag - up
180 View* mouse_pressed_handler_;
182 // The view currently handling enter / exit
183 View* mouse_move_handler_;
185 // The last view to handle a mouse click, so that we can determine if
186 // a double-click lands on the same view as its single-click part.
187 View* last_click_handler_;
189 // true if mouse_pressed_handler_ has been explicitly set
190 bool explicit_mouse_handler_;
192 // Last position/flag of a mouse press/drag. Used if capture stops and we need
193 // to synthesize a release.
194 int last_mouse_event_flags_;
195 int last_mouse_event_x_;
196 int last_mouse_event_y_;
198 // The View currently handling gesture events.
199 View* gesture_handler_;
201 // Used to indicate if the |gesture_handler_| member was set prior to the
202 // processing of the current event (i.e., if |gesture_handler_| was set
203 // by the dispatch of a previous gesture event).
204 // TODO(tdanderson): It may be possible to eliminate the need for this
205 // member if |event_dispatch_target_| can be used in
206 // its place.
207 bool gesture_handler_set_before_processing_;
209 scoped_ptr<internal::PreEventDispatchHandler> pre_dispatch_handler_;
210 scoped_ptr<internal::PostEventDispatchHandler> post_dispatch_handler_;
212 // Focus ---------------------------------------------------------------------
214 // The focus search algorithm.
215 FocusSearch focus_search_;
217 // Whether this root view belongs to the current active window.
218 // bool activated_;
220 // The parent FocusTraversable, used for focus traversal.
221 FocusTraversable* focus_traversable_parent_;
223 // The View that contains this RootView. This is used when we have RootView
224 // wrapped inside native components, and is used for the focus traversal.
225 View* focus_traversable_parent_view_;
227 View* event_dispatch_target_;
228 View* old_dispatch_target_;
230 // Drag and drop -------------------------------------------------------------
232 // Tracks drag state for a view.
233 View::DragInfo drag_info_;
235 DISALLOW_IMPLICIT_CONSTRUCTORS(RootView);
238 } // namespace internal
239 } // namespace views
241 #endif // UI_VIEWS_WIDGET_ROOT_VIEW_H_