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_WIDGET_H_ | |
6 #define VIEWS_WIDGET_WIDGET_H_ | |
7 #pragma once | |
8 | |
9 #include <set> | |
10 #include <stack> | |
11 | |
12 #include "base/gtest_prod_util.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/observer_list.h" | |
15 #include "ui/base/accessibility/accessibility_types.h" | |
16 #include "ui/base/ui_base_types.h" | |
17 #include "ui/gfx/native_widget_types.h" | |
18 #include "ui/gfx/rect.h" | |
19 #include "ui/views/focus/focus_manager.h" | |
20 #include "ui/views/window/client_view.h" | |
21 #include "ui/views/window/non_client_view.h" | |
22 #include "views/widget/native_widget_delegate.h" | |
23 | |
24 #if defined(OS_WIN) | |
25 // Windows headers define macros for these function names which screw with us. | |
26 #if defined(IsMaximized) | |
27 #undef IsMaximized | |
28 #endif | |
29 #if defined(IsMinimized) | |
30 #undef IsMinimized | |
31 #endif | |
32 #if defined(CreateWindow) | |
33 #undef CreateWindow | |
34 #endif | |
35 #endif | |
36 | |
37 namespace gfx { | |
38 class Canvas; | |
39 class Point; | |
40 class Rect; | |
41 } | |
42 | |
43 namespace ui { | |
44 class Accelerator; | |
45 class Compositor; | |
46 class OSExchangeData; | |
47 class ThemeProvider; | |
48 enum TouchStatus; | |
49 } | |
50 using ui::ThemeProvider; | |
51 | |
52 namespace views { | |
53 | |
54 class DefaultThemeProvider; | |
55 class InputMethod; | |
56 class NativeWidget; | |
57 class NonClientFrameView; | |
58 class ScopedEvent; | |
59 class View; | |
60 class WidgetDelegate; | |
61 namespace internal { | |
62 class NativeWidgetPrivate; | |
63 class RootView; | |
64 } | |
65 | |
66 //////////////////////////////////////////////////////////////////////////////// | |
67 // Widget class | |
68 // | |
69 // Encapsulates the platform-specific rendering, event receiving and widget | |
70 // management aspects of the UI framework. | |
71 // | |
72 // Owns a RootView and thus a View hierarchy. Can contain child Widgets. | |
73 // Widget is a platform-independent type that communicates with a platform or | |
74 // context specific NativeWidget implementation. | |
75 // | |
76 // A special note on ownership: | |
77 // | |
78 // Depending on the value of the InitParams' ownership field, the Widget | |
79 // either owns or is owned by its NativeWidget: | |
80 // | |
81 // ownership = NATIVE_WIDGET_OWNS_WIDGET (default) | |
82 // The Widget instance is owned by its NativeWidget. When the NativeWidget | |
83 // is destroyed (in response to a native destruction message), it deletes | |
84 // the Widget from its destructor. | |
85 // ownership = WIDGET_OWNS_NATIVE_WIDGET (non-default) | |
86 // The Widget instance owns its NativeWidget. This state implies someone | |
87 // else wants to control the lifetime of this object. When they destroy | |
88 // the Widget it is responsible for destroying the NativeWidget (from its | |
89 // destructor). | |
90 // | |
91 class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, | |
92 public FocusTraversable { | |
93 public: | |
94 // Observers can listen to various events on the Widgets. | |
95 class VIEWS_EXPORT Observer { | |
96 public: | |
97 virtual void OnWidgetClosing(Widget* widget) {} | |
98 virtual void OnWidgetVisibilityChanged(Widget* widget, bool visible) {} | |
99 virtual void OnWidgetActivationChanged(Widget* widget, bool active) {} | |
100 }; | |
101 | |
102 typedef std::set<Widget*> Widgets; | |
103 | |
104 enum FrameType { | |
105 FRAME_TYPE_DEFAULT, // Use whatever the default would be. | |
106 FRAME_TYPE_FORCE_CUSTOM, // Force the custom frame. | |
107 FRAME_TYPE_FORCE_NATIVE // Force the native frame. | |
108 }; | |
109 | |
110 struct VIEWS_EXPORT InitParams { | |
111 enum Type { | |
112 TYPE_WINDOW, // A decorated Window, like a frame window. | |
113 // Widgets of TYPE_WINDOW will have a NonClientView. | |
114 TYPE_WINDOW_FRAMELESS, | |
115 // An undecorated Window. | |
116 TYPE_CONTROL, // A control, like a button. | |
117 TYPE_POPUP, // An undecorated Window, with transient properties. | |
118 TYPE_MENU, // An undecorated Window, with transient properties | |
119 // specialized to menus. | |
120 TYPE_TOOLTIP, | |
121 TYPE_BUBBLE, | |
122 }; | |
123 enum Ownership { | |
124 // Default. Creator is not responsible for managing the lifetime of the | |
125 // Widget, it is destroyed when the corresponding NativeWidget is | |
126 // destroyed. | |
127 NATIVE_WIDGET_OWNS_WIDGET, | |
128 // Used when the Widget is owned by someone other than the NativeWidget, | |
129 // e.g. a scoped_ptr in tests. | |
130 WIDGET_OWNS_NATIVE_WIDGET | |
131 }; | |
132 | |
133 InitParams(); | |
134 explicit InitParams(Type type); | |
135 | |
136 // If |parent_widget| is non-null, it's native view is returned, otherwise | |
137 // |parent| is returned. | |
138 gfx::NativeView GetParent() const; | |
139 | |
140 Type type; | |
141 // If NULL, a default implementation will be constructed. | |
142 WidgetDelegate* delegate; | |
143 bool child; | |
144 bool transient; | |
145 // If true, the widget may be fully or partially transparent. If false, | |
146 // we can perform optimizations based on the widget being fully opaque. | |
147 // Defaults to false. | |
148 bool transparent; | |
149 bool accept_events; | |
150 bool can_activate; | |
151 bool keep_on_top; | |
152 Ownership ownership; | |
153 bool mirror_origin_in_rtl; | |
154 bool has_dropshadow; | |
155 // Whether the widget should be maximized or minimized. | |
156 ui::WindowShowState show_state; | |
157 // Should the widget be double buffered? Default is false. | |
158 bool double_buffer; | |
159 gfx::NativeView parent; | |
160 Widget* parent_widget; | |
161 // Specifies the initial bounds of the Widget. Default is empty, which means | |
162 // the NativeWidget may specify a default size. | |
163 gfx::Rect bounds; | |
164 // When set, this value is used as the Widget's NativeWidget implementation. | |
165 // The Widget will not construct a default one. Default is NULL. | |
166 NativeWidget* native_widget; | |
167 bool top_level; | |
168 // Only used by NativeWidgetAura. Specifies whether the Layer created by | |
169 // aura::Window has a texture. The default is true. | |
170 bool create_texture_for_layer; | |
171 }; | |
172 | |
173 Widget(); | |
174 virtual ~Widget(); | |
175 | |
176 // Creates a decorated window Widget with the specified properties. | |
177 static Widget* CreateWindow(WidgetDelegate* delegate); | |
178 static Widget* CreateWindowWithParent(WidgetDelegate* delegate, | |
179 gfx::NativeWindow parent); | |
180 static Widget* CreateWindowWithBounds(WidgetDelegate* delegate, | |
181 const gfx::Rect& bounds); | |
182 static Widget* CreateWindowWithParentAndBounds(WidgetDelegate* delegate, | |
183 gfx::NativeWindow parent, | |
184 const gfx::Rect& bounds); | |
185 | |
186 // Enumerates all windows pertaining to us and notifies their | |
187 // view hierarchies that the locale has changed. | |
188 static void NotifyLocaleChanged(); | |
189 | |
190 // Closes all Widgets that aren't identified as "secondary widgets". Called | |
191 // during application shutdown when the last non-secondary widget is closed. | |
192 static void CloseAllSecondaryWidgets(); | |
193 | |
194 // Converts a rectangle from one Widget's coordinate system to another's. | |
195 // Returns false if the conversion couldn't be made, because either these two | |
196 // Widgets do not have a common ancestor or they are not on the screen yet. | |
197 // The value of |*rect| won't be changed when false is returned. | |
198 static bool ConvertRect(const Widget* source, | |
199 const Widget* target, | |
200 gfx::Rect* rect); | |
201 | |
202 // SetPureViews and IsPureViews update and return the state of a global | |
203 // setting that tracks whether to use available pure Views implementations. | |
204 static void SetPureViews(bool pure); | |
205 static bool IsPureViews(); | |
206 | |
207 // Retrieves the Widget implementation associated with the given | |
208 // NativeView or Window, or NULL if the supplied handle has no associated | |
209 // Widget. | |
210 static Widget* GetWidgetForNativeView(gfx::NativeView native_view); | |
211 static Widget* GetWidgetForNativeWindow(gfx::NativeWindow native_window); | |
212 | |
213 // Retrieves the top level widget in a native view hierarchy | |
214 // starting at |native_view|. Top level widget is a widget with | |
215 // TYPE_WINDOW, TYPE_WINDOW_FRAMELESS, POPUP or MENU and has its own | |
216 // focus manager. This may be itself if the |native_view| is top level, | |
217 // or NULL if there is no toplevel in a native view hierarchy. | |
218 static Widget* GetTopLevelWidgetForNativeView(gfx::NativeView native_view); | |
219 | |
220 // Returns all Widgets in |native_view|'s hierarchy, including itself if | |
221 // it is one. | |
222 static void GetAllChildWidgets(gfx::NativeView native_view, | |
223 Widgets* children); | |
224 | |
225 // Re-parent a NativeView and notify all Widgets in |native_view|'s hierarchy | |
226 // of the change. | |
227 static void ReparentNativeView(gfx::NativeView native_view, | |
228 gfx::NativeView new_parent); | |
229 | |
230 // Returns the preferred size of the contents view of this window based on | |
231 // its localized size data. The width in cols is held in a localized string | |
232 // resource identified by |col_resource_id|, the height in the same fashion. | |
233 // TODO(beng): This should eventually live somewhere else, probably closer to | |
234 // ClientView. | |
235 static int GetLocalizedContentsWidth(int col_resource_id); | |
236 static int GetLocalizedContentsHeight(int row_resource_id); | |
237 static gfx::Size GetLocalizedContentsSize(int col_resource_id, | |
238 int row_resource_id); | |
239 | |
240 // Enable/Disable debug paint. | |
241 static void SetDebugPaintEnabled(bool enabled); | |
242 static bool IsDebugPaintEnabled(); | |
243 | |
244 // Returns true if the specified type requires a NonClientView. | |
245 static bool RequiresNonClientView(InitParams::Type type); | |
246 | |
247 void Init(const InitParams& params); | |
248 | |
249 // Returns the gfx::NativeView associated with this Widget. | |
250 gfx::NativeView GetNativeView() const; | |
251 | |
252 // Returns the gfx::NativeWindow associated with this Widget. This may return | |
253 // NULL on some platforms if the widget was created with a type other than | |
254 // TYPE_WINDOW. | |
255 gfx::NativeWindow GetNativeWindow() const; | |
256 | |
257 // Add/remove observer. | |
258 void AddObserver(Observer* observer); | |
259 void RemoveObserver(Observer* observer); | |
260 bool HasObserver(Observer* observer); | |
261 | |
262 // Returns the accelerator given a command id. Returns false if there is | |
263 // no accelerator associated with a given id, which is a common condition. | |
264 virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator); | |
265 | |
266 // Forwarded from the RootView so that the widget can do any cleanup. | |
267 void ViewHierarchyChanged(bool is_add, View* parent, View* child); | |
268 | |
269 // Performs any necessary cleanup and forwards to RootView. | |
270 void NotifyNativeViewHierarchyChanged(bool attached, | |
271 gfx::NativeView native_view); | |
272 | |
273 // Returns the top level widget in a hierarchy (see is_top_level() for | |
274 // the definition of top level widget.) Will return NULL if called | |
275 // before the widget is attached to the top level widget's hierarchy. | |
276 Widget* GetTopLevelWidget(); | |
277 const Widget* GetTopLevelWidget() const; | |
278 | |
279 // Gets/Sets the WidgetDelegate. | |
280 WidgetDelegate* widget_delegate() const { return widget_delegate_; } | |
281 | |
282 // Sets the specified view as the contents of this Widget. There can only | |
283 // be one contents view child of this Widget's RootView. This view is sized to | |
284 // fit the entire size of the RootView. The RootView takes ownership of this | |
285 // View, unless it is set as not being parent-owned. | |
286 void SetContentsView(View* view); | |
287 View* GetContentsView(); | |
288 | |
289 // Returns the bounds of the Widget in screen coordinates. | |
290 gfx::Rect GetWindowScreenBounds() const; | |
291 | |
292 // Returns the bounds of the Widget's client area in screen coordinates. | |
293 gfx::Rect GetClientAreaScreenBounds() const; | |
294 | |
295 // Retrieves the restored bounds for the window. | |
296 gfx::Rect GetRestoredBounds() const; | |
297 | |
298 // Sizes and/or places the widget to the specified bounds, size or position. | |
299 void SetBounds(const gfx::Rect& bounds); | |
300 void SetSize(const gfx::Size& size); | |
301 | |
302 // Like SetBounds(), but ensures the Widget is fully visible on screen, | |
303 // resizing and/or repositioning as necessary. This is only useful for | |
304 // non-child widgets. | |
305 void SetBoundsConstrained(const gfx::Rect& bounds); | |
306 | |
307 // Places the widget in front of the specified widget in z-order. | |
308 void MoveAboveWidget(Widget* widget); | |
309 void MoveAbove(gfx::NativeView native_view); | |
310 void MoveToTop(); | |
311 | |
312 // Sets a shape on the widget. This takes ownership of shape. | |
313 void SetShape(gfx::NativeRegion shape); | |
314 | |
315 // Hides the widget then closes it after a return to the message loop. | |
316 virtual void Close(); | |
317 | |
318 // TODO(beng): Move off public API. | |
319 // Closes the widget immediately. Compare to |Close|. This will destroy the | |
320 // window handle associated with this Widget, so should not be called from | |
321 // any code that expects it to be valid beyond this call. | |
322 void CloseNow(); | |
323 | |
324 // Toggles the enable state for the Close button (and the Close menu item in | |
325 // the system menu). | |
326 void EnableClose(bool enable); | |
327 | |
328 // Shows or hides the widget, without changing activation state. | |
329 virtual void Show(); | |
330 void Hide(); | |
331 | |
332 // Like Show(), but does not activate the window. | |
333 void ShowInactive(); | |
334 | |
335 // Activates the widget, assuming it already exists and is visible. | |
336 void Activate(); | |
337 | |
338 // Deactivates the widget, making the next window in the Z order the active | |
339 // window. | |
340 void Deactivate(); | |
341 | |
342 // Returns whether the Widget is the currently active window. | |
343 virtual bool IsActive() const; | |
344 | |
345 // Prevents the window from being rendered as deactivated. This state is | |
346 // reset automatically as soon as the window becomes activated again. There is | |
347 // no ability to control the state through this API as this leads to sync | |
348 // problems. | |
349 void DisableInactiveRendering(); | |
350 | |
351 // Sets the widget to be on top of all other widgets in the windowing system. | |
352 void SetAlwaysOnTop(bool on_top); | |
353 | |
354 // Maximizes/minimizes/restores the window. | |
355 void Maximize(); | |
356 void Minimize(); | |
357 void Restore(); | |
358 | |
359 // Whether or not the window is maximized or minimized. | |
360 virtual bool IsMaximized() const; | |
361 bool IsMinimized() const; | |
362 | |
363 // Accessors for fullscreen state. | |
364 void SetFullscreen(bool fullscreen); | |
365 bool IsFullscreen() const; | |
366 | |
367 // Sets the opacity of the widget. This may allow widgets behind the widget | |
368 // in the Z-order to become visible, depending on the capabilities of the | |
369 // underlying windowing system. Note that the caller must then schedule a | |
370 // repaint to allow this change to take effect. | |
371 void SetOpacity(unsigned char opacity); | |
372 | |
373 // Sets whether or not the window should show its frame as a "transient drag | |
374 // frame" - slightly transparent and without the standard window controls. | |
375 void SetUseDragFrame(bool use_drag_frame); | |
376 | |
377 // Returns the View at the root of the View hierarchy contained by this | |
378 // Widget. | |
379 View* GetRootView(); | |
380 const View* GetRootView() const; | |
381 | |
382 // A secondary widget is one that is automatically closed (via Close()) when | |
383 // all non-secondary widgets are closed. | |
384 // Default is true. | |
385 // TODO(beng): This is an ugly API, should be handled implicitly via | |
386 // transience. | |
387 void set_is_secondary_widget(bool is_secondary_widget) { | |
388 is_secondary_widget_ = is_secondary_widget; | |
389 } | |
390 bool is_secondary_widget() const { return is_secondary_widget_; } | |
391 | |
392 // Returns whether the Widget is visible to the user. | |
393 virtual bool IsVisible() const; | |
394 | |
395 // Returns whether the Widget is customized for accessibility. | |
396 bool IsAccessibleWidget() const; | |
397 | |
398 // Returns the ThemeProvider that provides theme resources for this Widget. | |
399 virtual ThemeProvider* GetThemeProvider() const; | |
400 | |
401 // Returns the FocusManager for this widget. | |
402 // Note that all widgets in a widget hierarchy share the same focus manager. | |
403 // TODO(beng): remove virtual. | |
404 virtual FocusManager* GetFocusManager(); | |
405 virtual const FocusManager* GetFocusManager() const; | |
406 | |
407 // Returns the InputMethod for this widget. | |
408 // Note that all widgets in a widget hierarchy share the same input method. | |
409 InputMethod* GetInputMethod(); | |
410 | |
411 // Starts a drag operation for the specified view. This blocks until the drag | |
412 // operation completes. |view| can be NULL. | |
413 // If the view is non-NULL it can be accessed during the drag by calling | |
414 // dragged_view(). If the view has not been deleted during the drag, | |
415 // OnDragDone() is called on it. | |
416 void RunShellDrag(View* view, const ui::OSExchangeData& data, int operation); | |
417 | |
418 // Returns the view that requested the current drag operation via | |
419 // RunShellDrag(), or NULL if there is no such view or drag operation. | |
420 View* dragged_view() { return dragged_view_; } | |
421 | |
422 // Adds the specified |rect| in client area coordinates to the rectangle to be | |
423 // redrawn. | |
424 void SchedulePaintInRect(const gfx::Rect& rect); | |
425 | |
426 // Sets the currently visible cursor. If |cursor| is NULL, the cursor used | |
427 // before the current is restored. | |
428 void SetCursor(gfx::NativeCursor cursor); | |
429 | |
430 // Resets the last move flag so that we can go around the optimization | |
431 // that disregards duplicate mouse moves when ending animation requires | |
432 // a new hit-test to do some highlighting as in TabStrip::RemoveTabAnimation | |
433 // to cause the close button to highlight. | |
434 void ResetLastMouseMoveFlag(); | |
435 | |
436 // Sets/Gets a native window property on the underlying native window object. | |
437 // Returns NULL if the property does not exist. Setting the property value to | |
438 // NULL removes the property. | |
439 void SetNativeWindowProperty(const char* name, void* value); | |
440 void* GetNativeWindowProperty(const char* name) const; | |
441 | |
442 // Tell the window to update its title from the delegate. | |
443 void UpdateWindowTitle(); | |
444 | |
445 // Tell the window to update its icon from the delegate. | |
446 void UpdateWindowIcon(); | |
447 | |
448 // Retrieves the focus traversable for this widget. | |
449 FocusTraversable* GetFocusTraversable(); | |
450 | |
451 // Notifies the view hierarchy contained in this widget that theme resources | |
452 // changed. | |
453 void ThemeChanged(); | |
454 | |
455 // Notifies the view hierarchy contained in this widget that locale resources | |
456 // changed. | |
457 void LocaleChanged(); | |
458 | |
459 void SetFocusTraversableParent(FocusTraversable* parent); | |
460 void SetFocusTraversableParentView(View* parent_view); | |
461 | |
462 // Clear native focus set to the Widget's NativeWidget. | |
463 void ClearNativeFocus(); | |
464 | |
465 // Sets the focus to |native_view|. | |
466 void FocusNativeView(gfx::NativeView native_view); | |
467 | |
468 // Updates the frame after an event caused it to be changed. | |
469 virtual void UpdateFrameAfterFrameChange(); | |
470 | |
471 void set_frame_type(FrameType frame_type) { frame_type_ = frame_type; } | |
472 FrameType frame_type() const { return frame_type_; } | |
473 | |
474 // Creates an appropriate NonClientFrameView for this widget. The | |
475 // WidgetDelegate is given the first opportunity to create one, followed by | |
476 // the NativeWidget implementation. If both return NULL, a default one is | |
477 // created. | |
478 virtual NonClientFrameView* CreateNonClientFrameView(); | |
479 | |
480 // Whether we should be using a native frame. | |
481 bool ShouldUseNativeFrame() const; | |
482 | |
483 // Forces the frame into the alternate frame type (custom or native) depending | |
484 // on its current state. | |
485 void DebugToggleFrameType(); | |
486 | |
487 // Tell the window that something caused the frame type to change. | |
488 void FrameTypeChanged(); | |
489 | |
490 NonClientView* non_client_view() { | |
491 return const_cast<NonClientView*>( | |
492 const_cast<const Widget*>(this)->non_client_view()); | |
493 } | |
494 const NonClientView* non_client_view() const { | |
495 return non_client_view_; | |
496 } | |
497 | |
498 ClientView* client_view() { | |
499 return const_cast<ClientView*>( | |
500 const_cast<const Widget*>(this)->client_view()); | |
501 } | |
502 const ClientView* client_view() const { | |
503 // non_client_view_ may be NULL, especially during creation. | |
504 return non_client_view_ ? non_client_view_->client_view() : NULL; | |
505 } | |
506 | |
507 const ui::Compositor* GetCompositor() const; | |
508 ui::Compositor* GetCompositor(); | |
509 | |
510 // Invokes method of same name on the NativeWidget. | |
511 void CalculateOffsetToAncestorWithLayer(gfx::Point* offset, | |
512 ui::Layer** layer_parent); | |
513 | |
514 // Invokes method of same name on the NativeWidget. | |
515 void ReorderLayers(); | |
516 | |
517 // Notifies assistive technology that an accessibility event has | |
518 // occurred on |view|, such as when the view is focused or when its | |
519 // value changes. Pass true for |send_native_event| except for rare | |
520 // cases where the view is a native control that's already sending a | |
521 // native accessibility event and the duplicate event would cause | |
522 // problems. | |
523 void NotifyAccessibilityEvent( | |
524 View* view, | |
525 ui::AccessibilityTypes::Event event_type, | |
526 bool send_native_event); | |
527 | |
528 const NativeWidget* native_widget() const; | |
529 NativeWidget* native_widget(); | |
530 | |
531 internal::NativeWidgetPrivate* native_widget_private() { | |
532 return native_widget_; | |
533 } | |
534 const internal::NativeWidgetPrivate* native_widget_private() const { | |
535 return native_widget_; | |
536 } | |
537 | |
538 // Returns the current event being processed. If there are multiple events | |
539 // being processed at the same time (e.g. one event triggers another event), | |
540 // then the most recent event is returned. Returns NULL if no event is being | |
541 // processed. | |
542 const Event* GetCurrentEvent(); | |
543 | |
544 // Invoked when the tooltip text changes for the specified views. | |
545 void TooltipTextChanged(View* view); | |
546 | |
547 // Sets-up the focus manager with the view that should have focus when the | |
548 // window is shown the first time. Returns true if the initial focus has been | |
549 // set or the widget should not set the initial focus, or false if the caller | |
550 // should set the initial focus (if any). | |
551 bool SetInitialFocus(); | |
552 | |
553 void set_focus_on_creation(bool focus_on_creation) { | |
554 focus_on_creation_ = focus_on_creation; | |
555 } | |
556 | |
557 // Converts the |point| in ancestor's coordinate to this widget's coordinates. | |
558 // Returns false if |ancestor| is not an ancestor of this widget. | |
559 // The receiver has to be pure views widget (NativeWidgetViews) and | |
560 // ancestor can be of any type. | |
561 bool ConvertPointFromAncestor( | |
562 const Widget* ancestor, gfx::Point* point) const; | |
563 | |
564 // Returns a View* that any child Widgets backed by NativeWidgetViews | |
565 // are added to. The default implementation returns the contents view | |
566 // if it exists and the root view otherwise. | |
567 virtual View* GetChildViewParent(); | |
568 | |
569 // True if the widget is considered top level widget. Top level widget | |
570 // is a widget of TYPE_WINDOW, TYPE_WINDOW_FRAMELESS, BUBBLE, POPUP or MENU, | |
571 // and has a focus manager and input method object associated with it. | |
572 // TYPE_CONTROL and TYPE_TOOLTIP is not considered top level. | |
573 bool is_top_level() const { return is_top_level_; } | |
574 | |
575 // Returns the bounds of work area in the screen that Widget belongs to. | |
576 gfx::Rect GetWorkAreaBoundsInScreen() const; | |
577 | |
578 // Overridden from NativeWidgetDelegate: | |
579 virtual bool IsModal() const OVERRIDE; | |
580 virtual bool IsDialogBox() const OVERRIDE; | |
581 virtual bool CanActivate() const OVERRIDE; | |
582 virtual bool IsInactiveRenderingDisabled() const OVERRIDE; | |
583 virtual void EnableInactiveRendering() OVERRIDE; | |
584 virtual void OnNativeWidgetActivationChanged(bool active) OVERRIDE; | |
585 virtual void OnNativeFocus(gfx::NativeView focused_view) OVERRIDE; | |
586 virtual void OnNativeBlur(gfx::NativeView focused_view) OVERRIDE; | |
587 virtual void OnNativeWidgetVisibilityChanged(bool visible) OVERRIDE; | |
588 virtual void OnNativeWidgetCreated() OVERRIDE; | |
589 virtual void OnNativeWidgetDestroying() OVERRIDE; | |
590 virtual void OnNativeWidgetDestroyed() OVERRIDE; | |
591 virtual gfx::Size GetMinimumSize() OVERRIDE; | |
592 virtual void OnNativeWidgetSizeChanged(const gfx::Size& new_size) OVERRIDE; | |
593 virtual void OnNativeWidgetBeginUserBoundsChange() OVERRIDE; | |
594 virtual void OnNativeWidgetEndUserBoundsChange() OVERRIDE; | |
595 virtual bool HasFocusManager() const OVERRIDE; | |
596 virtual bool OnNativeWidgetPaintAccelerated( | |
597 const gfx::Rect& dirty_region) OVERRIDE; | |
598 virtual void OnNativeWidgetPaint(gfx::Canvas* canvas) OVERRIDE; | |
599 virtual int GetNonClientComponent(const gfx::Point& point) OVERRIDE; | |
600 virtual bool OnKeyEvent(const KeyEvent& event) OVERRIDE; | |
601 virtual bool OnMouseEvent(const MouseEvent& event) OVERRIDE; | |
602 virtual void OnMouseCaptureLost() OVERRIDE; | |
603 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; | |
604 virtual bool ExecuteCommand(int command_id) OVERRIDE; | |
605 virtual InputMethod* GetInputMethodDirect() OVERRIDE; | |
606 virtual Widget* AsWidget() OVERRIDE; | |
607 virtual const Widget* AsWidget() const OVERRIDE; | |
608 | |
609 // Overridden from FocusTraversable: | |
610 virtual FocusSearch* GetFocusSearch() OVERRIDE; | |
611 virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE; | |
612 virtual View* GetFocusTraversableParentView() OVERRIDE; | |
613 | |
614 protected: | |
615 // Creates the RootView to be used within this Widget. Subclasses may override | |
616 // to create custom RootViews that do specialized event processing. | |
617 // TODO(beng): Investigate whether or not this is needed. | |
618 virtual internal::RootView* CreateRootView(); | |
619 | |
620 // Provided to allow the NativeWidget implementations to destroy the RootView | |
621 // _before_ the focus manager/tooltip manager. | |
622 // TODO(beng): remove once we fold those objects onto this one. | |
623 void DestroyRootView(); | |
624 | |
625 private: | |
626 // TODO(beng): Remove NativeWidgetGtk's dependence on the mouse state flags. | |
627 friend class NativeWidgetGtk; | |
628 | |
629 friend class NativeTextfieldViewsTest; | |
630 friend class NativeComboboxViewsTest; | |
631 friend class ScopedEvent; | |
632 | |
633 // Returns whether capture should be released on mouse release. | |
634 virtual bool ShouldReleaseCaptureOnMouseReleased() const; | |
635 | |
636 // Sets the value of |disable_inactive_rendering_|. If the value changes, | |
637 // both the NonClientView and WidgetDelegate are notified. | |
638 void SetInactiveRenderingDisabled(bool value); | |
639 | |
640 // Persists the window's restored position and "show" state using the | |
641 // window delegate. | |
642 void SaveWindowPlacement(); | |
643 | |
644 // Sizes and positions the window just after it is created. | |
645 void SetInitialBounds(const gfx::Rect& bounds); | |
646 | |
647 // Returns the bounds and "show" state from the delegate. Returns true if | |
648 // the delegate wants to use a specified bounds. | |
649 bool GetSavedWindowPlacement(gfx::Rect* bounds, | |
650 ui::WindowShowState* show_state); | |
651 | |
652 // Sets a different InputMethod instance to this widget. The instance | |
653 // must not be initialized, the ownership will be assumed by the widget. | |
654 // It's only for testing purpose. | |
655 void ReplaceInputMethod(InputMethod* input_method); | |
656 | |
657 internal::NativeWidgetPrivate* native_widget_; | |
658 | |
659 ObserverList<Observer> observers_; | |
660 | |
661 // Non-owned pointer to the Widget's delegate. May be NULL if no delegate is | |
662 // being used. | |
663 WidgetDelegate* widget_delegate_; | |
664 | |
665 // The root of the View hierarchy attached to this window. | |
666 // WARNING: see warning in tooltip_manager_ for ordering dependencies with | |
667 // this and tooltip_manager_. | |
668 scoped_ptr<internal::RootView> root_view_; | |
669 | |
670 // The View that provides the non-client area of the window (title bar, | |
671 // window controls, sizing borders etc). To use an implementation other than | |
672 // the default, this class must be sub-classed and this value set to the | |
673 // desired implementation before calling |InitWindow()|. | |
674 NonClientView* non_client_view_; | |
675 | |
676 // The focus manager keeping track of focus for this Widget and any of its | |
677 // children. NULL for non top-level widgets. | |
678 // WARNING: RootView's destructor calls into the FocusManager. As such, this | |
679 // must be destroyed AFTER root_view_. This is enforced in DestroyRootView(). | |
680 scoped_ptr<FocusManager> focus_manager_; | |
681 | |
682 // A theme provider to use when no other theme provider is specified. | |
683 scoped_ptr<DefaultThemeProvider> default_theme_provider_; | |
684 | |
685 // Valid for the lifetime of RunShellDrag(), indicates the view the drag | |
686 // started from. | |
687 View* dragged_view_; | |
688 | |
689 // The event stack. | |
690 std::stack<ScopedEvent*> event_stack_; | |
691 | |
692 // See class documentation for Widget above for a note about ownership. | |
693 InitParams::Ownership ownership_; | |
694 | |
695 // See set_is_secondary_widget(). | |
696 bool is_secondary_widget_; | |
697 | |
698 // The current frame type in use by this window. Defaults to | |
699 // FRAME_TYPE_DEFAULT. | |
700 FrameType frame_type_; | |
701 | |
702 // True when the window should be rendered as active, regardless of whether | |
703 // or not it actually is. | |
704 bool disable_inactive_rendering_; | |
705 | |
706 // Set to true if the widget is in the process of closing. | |
707 bool widget_closed_; | |
708 | |
709 // The saved "show" state for this window. See note in SetInitialBounds | |
710 // that explains why we save this. | |
711 ui::WindowShowState saved_show_state_; | |
712 | |
713 // The restored bounds used for the initial show. This is only used if | |
714 // |saved_show_state_| is maximized. | |
715 gfx::Rect initial_restored_bounds_; | |
716 | |
717 // Focus is automatically set to the view provided by the delegate | |
718 // when the widget is shown. Set this value to false to override | |
719 // initial focus for the widget. | |
720 bool focus_on_creation_; | |
721 | |
722 scoped_ptr<InputMethod> input_method_; | |
723 | |
724 // See |is_top_level()| accessor. | |
725 bool is_top_level_; | |
726 | |
727 // Tracks whether native widget has been initialized. | |
728 bool native_widget_initialized_; | |
729 | |
730 // TODO(beng): Remove NativeWidgetGtk's dependence on these: | |
731 // If true, the mouse is currently down. | |
732 bool is_mouse_button_pressed_; | |
733 | |
734 // TODO(beng): Remove NativeWidgetGtk's dependence on these: | |
735 // The following are used to detect duplicate mouse move events and not | |
736 // deliver them. Displaying a window may result in the system generating | |
737 // duplicate move events even though the mouse hasn't moved. | |
738 bool last_mouse_event_was_move_; | |
739 gfx::Point last_mouse_event_position_; | |
740 | |
741 DISALLOW_COPY_AND_ASSIGN(Widget); | |
742 }; | |
743 | |
744 } // namespace views | |
745 | |
746 #endif // VIEWS_WIDGET_WIDGET_H_ | |
OLD | NEW |