Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: views/widget/widget.h

Issue 7015051: Re-land: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/widget/tooltip_manager_gtk.cc ('k') | views/widget/widget.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef VIEWS_WIDGET_WIDGET_H_ 5 #ifndef VIEWS_WIDGET_WIDGET_H_
6 #define VIEWS_WIDGET_WIDGET_H_ 6 #define VIEWS_WIDGET_WIDGET_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 //////////////////////////////////////////////////////////////////////////////// 45 ////////////////////////////////////////////////////////////////////////////////
46 // Widget class 46 // Widget class
47 // 47 //
48 // Encapsulates the platform-specific rendering, event receiving and widget 48 // Encapsulates the platform-specific rendering, event receiving and widget
49 // management aspects of the UI framework. 49 // management aspects of the UI framework.
50 // 50 //
51 // Owns a RootView and thus a View hierarchy. Can contain child Widgets. 51 // Owns a RootView and thus a View hierarchy. Can contain child Widgets.
52 // Widget is a platform-independent type that communicates with a platform or 52 // Widget is a platform-independent type that communicates with a platform or
53 // context specific NativeWidget implementation. 53 // context specific NativeWidget implementation.
54 // 54 //
55 // TODO(beng): Note that this class being non-abstract means that we have a 55 // A special note on ownership:
56 // violation of Google style in that we are using multiple 56 //
57 // inheritance. The intention is to split this into a separate 57 // Depending on the value of "delete_on_destroy", the Widget either owns or
58 // object associated with but not equal to a NativeWidget 58 // is owned by its NativeWidget:
59 // implementation. Multiple inheritance is required for this 59 //
60 // transitional step. 60 // delete_on_destroy = true (default)
61 // The Widget instance is owned by its NativeWidget. When the NativeWidget
62 // is destroyed (in response to a native destruction message), it deletes
63 // the Widget from its destructor.
64 // delete_on_destroy = false (non-default)
65 // The Widget instance owns its NativeWidget. This state implies someone
66 // else wants to control the lifetime of this object. When they destroy
67 // the Widget it is responsible for destroying the NativeWidget (from its
68 // destructor).
61 // 69 //
62 class Widget : public internal::NativeWidgetDelegate, 70 class Widget : public internal::NativeWidgetDelegate,
63 public FocusTraversable { 71 public FocusTraversable {
64 public: 72 public:
65 struct InitParams { 73 struct InitParams {
66 enum Type { 74 enum Type {
67 TYPE_WINDOW, // A Window, like a frame window. 75 TYPE_WINDOW, // A Window, like a frame window.
68 TYPE_CONTROL, // A control, like a button. 76 TYPE_CONTROL, // A control, like a button.
69 TYPE_POPUP, // An undecorated Window, with transient properties. 77 TYPE_POPUP, // An undecorated Window, with transient properties.
70 TYPE_MENU // An undecorated Window, with transient properties 78 TYPE_MENU // An undecorated Window, with transient properties
71 // specialized to menus. 79 // specialized to menus.
72 }; 80 };
73 81
74 InitParams(); 82 InitParams();
75 explicit InitParams(Type type); 83 explicit InitParams(Type type);
76 84
77 Type type; 85 Type type;
78 bool child; 86 bool child;
87 bool transient;
79 bool transparent; 88 bool transparent;
80 bool accept_events; 89 bool accept_events;
81 bool can_activate; 90 bool can_activate;
82 bool keep_on_top; 91 bool keep_on_top;
83 bool delete_on_destroy; 92 bool delete_on_destroy;
84 bool mirror_origin_in_rtl; 93 bool mirror_origin_in_rtl;
85 bool has_dropshadow; 94 bool has_dropshadow;
86 // Should the widget be double buffered? Default is false. 95 // Should the widget be double buffered? Default is false.
87 bool double_buffer; 96 bool double_buffer;
88 gfx::NativeView parent; 97 gfx::NativeView parent;
89 Widget* parent_widget; 98 Widget* parent_widget;
90 gfx::Rect bounds; 99 gfx::Rect bounds;
91 NativeWidget* native_widget; 100 NativeWidget* native_widget;
92 }; 101 };
93 static InitParams WindowInitParams(); 102 static InitParams WindowInitParams();
94 103
95 Widget(); 104 Widget();
96 virtual ~Widget(); 105 virtual ~Widget();
97 106
98 // Creates a Widget instance with the supplied params.
99 static Widget* CreateWidget();
100
101 // Enumerates all windows pertaining to us and notifies their 107 // Enumerates all windows pertaining to us and notifies their
102 // view hierarchies that the locale has changed. 108 // view hierarchies that the locale has changed.
103 static void NotifyLocaleChanged(); 109 static void NotifyLocaleChanged();
104 110
111 // Closes all Widgets that aren't identified as "secondary widgets". Called
112 // during application shutdown when the last non-secondary widget is closed.
113 static void CloseAllSecondaryWidgets();
114
105 // Converts a rectangle from one Widget's coordinate system to another's. 115 // Converts a rectangle from one Widget's coordinate system to another's.
106 // Returns false if the conversion couldn't be made, because either these two 116 // Returns false if the conversion couldn't be made, because either these two
107 // Widgets do not have a common ancestor or they are not on the screen yet. 117 // Widgets do not have a common ancestor or they are not on the screen yet.
108 // The value of |*rect| won't be changed when false is returned. 118 // The value of |*rect| won't be changed when false is returned.
109 static bool ConvertRect(const Widget* source, 119 static bool ConvertRect(const Widget* source,
110 const Widget* target, 120 const Widget* target,
111 gfx::Rect* rect); 121 gfx::Rect* rect);
112 122
113 void Init(const InitParams& params); 123 void Init(const InitParams& params);
114 124
115 // Unconverted methods ------------------------------------------------------- 125 // Unconverted methods -------------------------------------------------------
116 126
117 // TODO(beng): 127 // TODO(beng): reorder, they've been converted now.
118 // Widget subclasses are still implementing these methods by overriding from
119 // here rather than by implementing NativeWidget.
120 128
121 // Returns the gfx::NativeView associated with this Widget. 129 // Returns the gfx::NativeView associated with this Widget.
122 virtual gfx::NativeView GetNativeView() const; 130 gfx::NativeView GetNativeView() const;
123 131
124 // Returns the gfx::NativeWindow associated with this Widget. This may return 132 // Returns the gfx::NativeWindow associated with this Widget. This may return
125 // NULL on some platforms if the widget was created with a type other than 133 // NULL on some platforms if the widget was created with a type other than
126 // TYPE_WINDOW. 134 // TYPE_WINDOW.
127 virtual gfx::NativeWindow GetNativeWindow() const; 135 gfx::NativeWindow GetNativeWindow() const;
128
129 // Starts a drag operation for the specified view. |point| is a position in
130 // |view| coordinates that the drag was initiated from.
131 virtual void GenerateMousePressedForView(View* view,
132 const gfx::Point& point);
133 136
134 // Returns the accelerator given a command id. Returns false if there is 137 // Returns the accelerator given a command id. Returns false if there is
135 // no accelerator associated with a given id, which is a common condition. 138 // no accelerator associated with a given id, which is a common condition.
136 virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator); 139 virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator);
137 140
138 // Returns the Window containing this Widget, or NULL if not contained in a 141 // Returns the Window containing this Widget, or NULL if not contained in a
139 // window. 142 // window.
140 virtual Window* GetWindow(); 143 Window* GetContainingWindow();
141 virtual const Window* GetWindow() const; 144 const Window* GetContainingWindow() const;
142 145
143 // Forwarded from the RootView so that the widget can do any cleanup. 146 // Forwarded from the RootView so that the widget can do any cleanup.
144 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); 147 void ViewHierarchyChanged(bool is_add, View* parent, View* child);
145 148
146 // Performs any necessary cleanup and forwards to RootView. 149 // Performs any necessary cleanup and forwards to RootView.
147 virtual void NotifyNativeViewHierarchyChanged(bool attached, 150 void NotifyNativeViewHierarchyChanged(bool attached,
148 gfx::NativeView native_view); 151 gfx::NativeView native_view);
149 152
150 // Converted methods --------------------------------------------------------- 153 // Converted methods ---------------------------------------------------------
151 154
152 // TODO(beng): 155 // TODO(beng):
153 // Widget subclasses are implementing these methods by implementing 156 // Widget subclasses are implementing these methods by implementing
154 // NativeWidget. Remove this comment once complete. 157 // NativeWidget. Remove this comment once complete.
155 158
156 // Returns the topmost Widget in a hierarchy. Will return NULL if called 159 // Returns the topmost Widget in a hierarchy. Will return NULL if called
157 // before the underlying Native Widget has been initialized. 160 // before the underlying Native Widget has been initialized.
158 Widget* GetTopLevelWidget(); 161 Widget* GetTopLevelWidget();
(...skipping 22 matching lines...) Expand all
181 void SetSize(const gfx::Size& size); 184 void SetSize(const gfx::Size& size);
182 185
183 // Places the widget in front of the specified widget in z-order. 186 // Places the widget in front of the specified widget in z-order.
184 void MoveAboveWidget(Widget* widget); 187 void MoveAboveWidget(Widget* widget);
185 void MoveAbove(gfx::NativeView native_view); 188 void MoveAbove(gfx::NativeView native_view);
186 189
187 // Sets a shape on the widget. This takes ownership of shape. 190 // Sets a shape on the widget. This takes ownership of shape.
188 void SetShape(gfx::NativeRegion shape); 191 void SetShape(gfx::NativeRegion shape);
189 192
190 // Hides the widget then closes it after a return to the message loop. 193 // Hides the widget then closes it after a return to the message loop.
191 void Close(); 194 virtual void Close();
192 195
193 // TODO(beng): Move off public API. 196 // TODO(beng): Move off public API.
194 // Closes the widget immediately. Compare to |Close|. This will destroy the 197 // Closes the widget immediately. Compare to |Close|. This will destroy the
195 // window handle associated with this Widget, so should not be called from 198 // window handle associated with this Widget, so should not be called from
196 // any code that expects it to be valid beyond this call. 199 // any code that expects it to be valid beyond this call.
197 void CloseNow(); 200 void CloseNow();
198 201
199 // Shows or hides the widget, without changing activation state. 202 // Shows or hides the widget, without changing activation state.
200 void Show(); 203 void Show();
201 void Hide(); 204 void Hide();
202 205
203 // Sets the opacity of the widget. This may allow widgets behind the widget 206 // Sets the opacity of the widget. This may allow widgets behind the widget
204 // in the Z-order to become visible, depending on the capabilities of the 207 // in the Z-order to become visible, depending on the capabilities of the
205 // underlying windowing system. Note that the caller must then schedule a 208 // underlying windowing system. Note that the caller must then schedule a
206 // repaint to allow this change to take effect. 209 // repaint to allow this change to take effect.
207 void SetOpacity(unsigned char opacity); 210 void SetOpacity(unsigned char opacity);
208 211
209 // Sets the widget to be on top of all other widgets in the windowing system. 212 // Sets the widget to be on top of all other widgets in the windowing system.
210 void SetAlwaysOnTop(bool on_top); 213 void SetAlwaysOnTop(bool on_top);
211 214
212 // Returns the RootView contained by this Widget. 215 // Returns the RootView contained by this Widget.
213 RootView* GetRootView(); 216 RootView* GetRootView();
214 217
218 // A secondary widget is one that is automatically closed (via Close()) when
219 // all non-secondary widgets are closed.
220 // Default is true.
221 // TODO(beng): This is an ugly API, should be handled implicitly via
222 // transience.
223 void set_is_secondary_widget(bool is_secondary_widget) {
224 is_secondary_widget_ = is_secondary_widget;
225 }
226 bool is_secondary_widget() const { return is_secondary_widget_; }
227
215 // Returns whether the Widget is visible to the user. 228 // Returns whether the Widget is visible to the user.
216 bool IsVisible() const; 229 bool IsVisible() const;
217 230
218 // Returns whether the Widget is the currently active window. 231 // Returns whether the Widget is the currently active window.
219 bool IsActive() const; 232 bool IsActive() const;
220 233
221 // Returns whether the Widget is customized for accessibility. 234 // Returns whether the Widget is customized for accessibility.
222 bool IsAccessibleWidget() const; 235 bool IsAccessibleWidget() const;
223 236
224 // Returns the ThemeProvider that provides theme resources for this Widget. 237 // Returns the ThemeProvider that provides theme resources for this Widget.
(...skipping 25 matching lines...) Expand all
250 View* dragged_view() { return dragged_view_; } 263 View* dragged_view() { return dragged_view_; }
251 264
252 // Adds the specified |rect| in client area coordinates to the rectangle to be 265 // Adds the specified |rect| in client area coordinates to the rectangle to be
253 // redrawn. 266 // redrawn.
254 void SchedulePaintInRect(const gfx::Rect& rect); 267 void SchedulePaintInRect(const gfx::Rect& rect);
255 268
256 // Sets the currently visible cursor. If |cursor| is NULL, the cursor used 269 // Sets the currently visible cursor. If |cursor| is NULL, the cursor used
257 // before the current is restored. 270 // before the current is restored.
258 void SetCursor(gfx::NativeCursor cursor); 271 void SetCursor(gfx::NativeCursor cursor);
259 272
273 // Resets the last move flag so that we can go around the optimization
274 // that disregards duplicate mouse moves when ending animation requires
275 // a new hit-test to do some highlighting as in TabStrip::RemoveTabAnimation
276 // to cause the close button to highlight.
277 void ResetLastMouseMoveFlag();
278
260 // Retrieves the focus traversable for this widget. 279 // Retrieves the focus traversable for this widget.
261 FocusTraversable* GetFocusTraversable(); 280 FocusTraversable* GetFocusTraversable();
262 281
263 // Notifies the view hierarchy contained in this widget that theme resources 282 // Notifies the view hierarchy contained in this widget that theme resources
264 // changed. 283 // changed.
265 void ThemeChanged(); 284 void ThemeChanged();
266 285
267 // Notifies the view hierarchy contained in this widget that locale resources 286 // Notifies the view hierarchy contained in this widget that locale resources
268 // changed. 287 // changed.
269 void LocaleChanged(); 288 void LocaleChanged();
270 289
271 void SetFocusTraversableParent(FocusTraversable* parent); 290 void SetFocusTraversableParent(FocusTraversable* parent);
272 void SetFocusTraversableParentView(View* parent_view); 291 void SetFocusTraversableParentView(View* parent_view);
273 292
274 const ui::Compositor* compositor() const { return compositor_.get(); } 293 const ui::Compositor* compositor() const { return compositor_.get(); }
275 ui::Compositor* compositor() { return compositor_.get(); } 294 ui::Compositor* compositor() { return compositor_.get(); }
276 295
277 // Notifies assistive technology that an accessibility event has 296 // Notifies assistive technology that an accessibility event has
278 // occurred on |view|, such as when the view is focused or when its 297 // occurred on |view|, such as when the view is focused or when its
279 // value changes. Pass true for |send_native_event| except for rare 298 // value changes. Pass true for |send_native_event| except for rare
280 // cases where the view is a native control that's already sending a 299 // cases where the view is a native control that's already sending a
281 // native accessibility event and the duplicate event would cause 300 // native accessibility event and the duplicate event would cause
282 // problems. 301 // problems.
283 virtual void NotifyAccessibilityEvent( 302 void NotifyAccessibilityEvent(
284 View* view, 303 View* view,
285 ui::AccessibilityTypes::Event event_type, 304 ui::AccessibilityTypes::Event event_type,
286 bool send_native_event) = 0; 305 bool send_native_event);
287 306
288 NativeWidget* native_widget() { return native_widget_; } 307 NativeWidget* native_widget() { return native_widget_; }
289 308
290 // Overridden from NativeWidgetDelegate: 309 // Overridden from NativeWidgetDelegate:
291 virtual void OnNativeFocus(gfx::NativeView focused_view) OVERRIDE; 310 virtual void OnNativeFocus(gfx::NativeView focused_view) OVERRIDE;
292 virtual void OnNativeBlur(gfx::NativeView focused_view) OVERRIDE; 311 virtual void OnNativeBlur(gfx::NativeView focused_view) OVERRIDE;
293 virtual void OnNativeWidgetCreated() OVERRIDE; 312 virtual void OnNativeWidgetCreated() OVERRIDE;
294 virtual void OnSizeChanged(const gfx::Size& new_size) OVERRIDE; 313 virtual void OnSizeChanged(const gfx::Size& new_size) OVERRIDE;
295 virtual bool HasFocusManager() const OVERRIDE; 314 virtual bool HasFocusManager() const OVERRIDE;
296 virtual bool OnNativeWidgetPaintAccelerated( 315 virtual bool OnNativeWidgetPaintAccelerated(
297 const gfx::Rect& dirty_region) OVERRIDE; 316 const gfx::Rect& dirty_region) OVERRIDE;
298 virtual void OnNativeWidgetPaint(gfx::Canvas* canvas) OVERRIDE; 317 virtual void OnNativeWidgetPaint(gfx::Canvas* canvas) OVERRIDE;
299 virtual bool OnKeyEvent(const KeyEvent& event) OVERRIDE; 318 virtual bool OnKeyEvent(const KeyEvent& event) OVERRIDE;
300 virtual bool OnMouseEvent(const MouseEvent& event) OVERRIDE; 319 virtual bool OnMouseEvent(const MouseEvent& event) OVERRIDE;
301 virtual void OnMouseCaptureLost() OVERRIDE; 320 virtual void OnMouseCaptureLost() OVERRIDE;
321 virtual Widget* AsWidget() OVERRIDE;
322 virtual const Widget* AsWidget() const OVERRIDE;
302 323
303 // Overridden from FocusTraversable: 324 // Overridden from FocusTraversable:
304 virtual FocusSearch* GetFocusSearch() OVERRIDE; 325 virtual FocusSearch* GetFocusSearch() OVERRIDE;
305 virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE; 326 virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE;
306 virtual View* GetFocusTraversableParentView() OVERRIDE; 327 virtual View* GetFocusTraversableParentView() OVERRIDE;
307 328
308 protected: 329 protected:
330 // TODO(beng): Remove WidgetGtk's dependence on the mouse state flags.
331 friend class WidgetGtk;
332
309 // Creates the RootView to be used within this Widget. Subclasses may override 333 // Creates the RootView to be used within this Widget. Subclasses may override
310 // to create custom RootViews that do specialized event processing. 334 // to create custom RootViews that do specialized event processing.
311 // TODO(beng): Investigate whether or not this is needed. 335 // TODO(beng): Investigate whether or not this is needed.
312 virtual RootView* CreateRootView(); 336 virtual RootView* CreateRootView();
313 337
314 // Provided to allow the WidgetWin/Gtk implementations to destroy the RootView 338 // Provided to allow the WidgetWin/Gtk implementations to destroy the RootView
315 // _before_ the focus manager/tooltip manager. 339 // _before_ the focus manager/tooltip manager.
316 // TODO(beng): remove once we fold those objects onto this one. 340 // TODO(beng): remove once we fold those objects onto this one.
317 void DestroyRootView(); 341 void DestroyRootView();
318 342
319 // TODO(beng): Temporarily provided as a way to associate the subclass'
320 // implementation of NativeWidget with this.
321 void set_native_widget(NativeWidget* native_widget) {
322 native_widget_ = native_widget;
323 }
324
325 // Used for testing. 343 // Used for testing.
326 void ReplaceFocusManager(FocusManager* focus_manager); 344 void ReplaceFocusManager(FocusManager* focus_manager);
327 345
346 // TODO(beng): Remove WidgetGtk's dependence on these:
328 // TODO(msw): Make this mouse state member private. 347 // TODO(msw): Make this mouse state member private.
329 // If true, the mouse is currently down. 348 // If true, the mouse is currently down.
330 bool is_mouse_button_pressed_; 349 bool is_mouse_button_pressed_;
331 350
351 // TODO(beng): Remove WidgetGtk's dependence on these:
332 // TODO(msw): Make these mouse state members private. 352 // TODO(msw): Make these mouse state members private.
333 // The following are used to detect duplicate mouse move events and not 353 // The following are used to detect duplicate mouse move events and not
334 // deliver them. Displaying a window may result in the system generating 354 // deliver them. Displaying a window may result in the system generating
335 // duplicate move events even though the mouse hasn't moved. 355 // duplicate move events even though the mouse hasn't moved.
336 bool last_mouse_event_was_move_; 356 bool last_mouse_event_was_move_;
337 gfx::Point last_mouse_event_position_; 357 gfx::Point last_mouse_event_position_;
338 358
339 private: 359 private:
340 // Try to create a compositor if one hasn't been created yet. 360 // Try to create a compositor if one hasn't been created yet.
341 void EnsureCompositor(); 361 void EnsureCompositor();
(...skipping 21 matching lines...) Expand all
363 // A theme provider to use when no other theme provider is specified. 383 // A theme provider to use when no other theme provider is specified.
364 scoped_ptr<DefaultThemeProvider> default_theme_provider_; 384 scoped_ptr<DefaultThemeProvider> default_theme_provider_;
365 385
366 // Valid for the lifetime of RunShellDrag(), indicates the view the drag 386 // Valid for the lifetime of RunShellDrag(), indicates the view the drag
367 // started from. 387 // started from.
368 View* dragged_view_; 388 View* dragged_view_;
369 389
370 // The compositor for accelerated drawing. 390 // The compositor for accelerated drawing.
371 scoped_refptr<ui::Compositor> compositor_; 391 scoped_refptr<ui::Compositor> compositor_;
372 392
393 // See class documentation for Widget above for a note about ownership.
394 bool delete_on_destroy_;
395
396 // See set_is_secondary_widget().
397 bool is_secondary_widget_;
398
373 DISALLOW_COPY_AND_ASSIGN(Widget); 399 DISALLOW_COPY_AND_ASSIGN(Widget);
374 }; 400 };
375 401
376 } // namespace views 402 } // namespace views
377 403
378 #endif // VIEWS_WIDGET_WIDGET_H_ 404 #endif // VIEWS_WIDGET_WIDGET_H_
OLDNEW
« no previous file with comments | « views/widget/tooltip_manager_gtk.cc ('k') | views/widget/widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698