widget.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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. 4 5#ifndef UI_VIEWS_WIDGET_WIDGET_H_ 6#define UI_VIEWS_WIDGET_WIDGET_H_ 7 8#include <set> 9#include <stack> 10#include <vector> 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/ui_base_types.h" 16#include "ui/compositor/layer_type.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/widget/native_widget_delegate.h" 21#include "ui/views/window/client_view.h" 22#include "ui/views/window/non_client_view.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 37namespace gfx { 38class Canvas; 39class Point; 40class Rect; 41} 42 43namespace ui { 44class Accelerator; 45class Compositor; 46class DefaultThemeProvider; 47class Layer; 48class NativeTheme; 49class OSExchangeData; 50class ThemeProvider; 51} 52 53namespace views { 54 55class DesktopRootWindowHost; 56class InputMethod; 57class NativeWidget; 58class NonClientFrameView; 59class ScopedEvent; 60class View; 61class WidgetDelegate; 62class WidgetObserver; 63 64namespace internal { 65class NativeWidgetPrivate; 66class RootView; 67} 68 69//////////////////////////////////////////////////////////////////////////////// 70// Widget class 71// 72// Encapsulates the platform-specific rendering, event receiving and widget 73// management aspects of the UI framework. 74// 75// Owns a RootView and thus a View hierarchy. Can contain child Widgets. 76// Widget is a platform-independent type that communicates with a platform or 77// context specific NativeWidget implementation. 78// 79// A special note on ownership: 80// 81// Depending on the value of the InitParams' ownership field, the Widget 82// either owns or is owned by its NativeWidget: 83// 84// ownership = NATIVE_WIDGET_OWNS_WIDGET (default) 85// The Widget instance is owned by its NativeWidget. When the NativeWidget 86// is destroyed (in response to a native destruction message), it deletes 87// the Widget from its destructor. 88// ownership = WIDGET_OWNS_NATIVE_WIDGET (non-default) 89// The Widget instance owns its NativeWidget. This state implies someone 90// else wants to control the lifetime of this object. When they destroy 91// the Widget it is responsible for destroying the NativeWidget (from its 92// destructor). 93// 94class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, 95 public FocusTraversable { 96 public: 97 typedef std::set<Widget*> Widgets; 98 99 enum FrameType { 100 FRAME_TYPE_DEFAULT, // Use whatever the default would be. 101 FRAME_TYPE_FORCE_CUSTOM, // Force the custom frame. 102 FRAME_TYPE_FORCE_NATIVE // Force the native frame. 103 }; 104 105 // Result from RunMoveLoop(). 106 enum MoveLoopResult { 107 // The move loop completed successfully. 108 MOVE_LOOP_SUCCESSFUL, 109 110 // The user canceled the move loop. 111 MOVE_LOOP_CANCELED 112 }; 113 114 // Source that initiated the move loop. 115 enum MoveLoopSource { 116 MOVE_LOOP_SOURCE_MOUSE, 117 MOVE_LOOP_SOURCE_TOUCH, 118 }; 119 120 struct VIEWS_EXPORT InitParams { 121 enum Type { 122 TYPE_WINDOW, // A decorated Window, like a frame window. 123 // Widgets of TYPE_WINDOW will have a NonClientView. 124 TYPE_PANEL, // Always on top window managed by PanelManager. 125 // Widgets of TYPE_PANEL will have a NonClientView. 126 TYPE_WINDOW_FRAMELESS, 127 // An undecorated Window. 128 TYPE_CONTROL, // A control, like a button. 129 TYPE_POPUP, // An undecorated Window, with transient properties. 130 TYPE_MENU, // An undecorated Window, with transient properties 131 // specialized to menus. 132 TYPE_TOOLTIP, 133 TYPE_BUBBLE, 134 }; 135 136 enum Ownership { 137 // Default. Creator is not responsible for managing the lifetime of the 138 // Widget, it is destroyed when the corresponding NativeWidget is 139 // destroyed. 140 NATIVE_WIDGET_OWNS_WIDGET, 141 // Used when the Widget is owned by someone other than the NativeWidget, 142 // e.g. a scoped_ptr in tests. 143 WIDGET_OWNS_NATIVE_WIDGET 144 }; 145 146 InitParams(); 147 explicit InitParams(Type type); 148 149 150 // Will return the first of the following that isn't NULL: the native view, 151 // |parent|, |context|. 152 gfx::NativeView GetContext() const; 153 154 Type type; 155 // If NULL, a default implementation will be constructed. 156 WidgetDelegate* delegate; 157 bool child; 158 bool transient; 159 // If true, the widget may be fully or partially transparent. If false, 160 // we can perform optimizations based on the widget being fully opaque. 161 // For window widgets, defaults to ViewsDelegate::UseTransparentWindows(). 162 // Defaults to false for non-window widgets. 163 bool transparent; 164 bool accept_events; 165 bool can_activate; 166 bool keep_on_top; 167 Ownership ownership; 168 bool mirror_origin_in_rtl; 169 bool has_dropshadow; 170 // Only used by NativeWidgetWin. Specifies that the system default caption 171 // and icon should not be rendered, and that the client area should be 172 // equivalent to the window area. 173 bool remove_standard_frame; 174 // Only used by ShellWindow on Windows. Specifies that the default icon of 175 // packaged app should be the system default icon. 176 bool use_system_default_icon; 177 // Whether the widget should be maximized or minimized. 178 ui::WindowShowState show_state; 179 // Should the widget be double buffered? Default is false. 180 bool double_buffer; 181 gfx::NativeView parent; 182 // Specifies the initial bounds of the Widget. Default is empty, which means 183 // the NativeWidget may specify a default size. If the parent is specified, 184 // |bounds| is in the parent's coordinate system. If the parent is not 185 // specified, it's in screen's global coordinate system. 186 gfx::Rect bounds; 187 // When set, this value is used as the Widget's NativeWidget implementation. 188 // The Widget will not construct a default one. Default is NULL. 189 NativeWidget* native_widget; 190 // Aura-only. Provides a DesktopRootWindowHost implementation to use instead 191 // of the default one. 192 // TODO(beng): Figure out if there's a better way to expose this, e.g. get 193 // rid of NW subclasses and do this all via message handling. 194 DesktopRootWindowHost* desktop_root_window_host; 195 // Whether this window is intended to be a toplevel window with no 196 // attachment to any other window. (This may be a transient window if 197 // |parent| is set.) 198 bool top_level; 199 // Only used by NativeWidgetAura. Specifies the type of layer for the 200 // aura::Window. Default is LAYER_TEXTURED. 201 ui::LayerType layer_type; 202 // Only used by Aura. Provides a context window whose RootWindow is 203 // consulted during widget creation to determine where in the Window 204 // hierarchy this widget should be placed. (This is separate from |parent|; 205 // if you pass a RootWindow to |parent|, your window will be parented to 206 // |parent|. If you pass a RootWindow to |context|, we ask that RootWindow 207 // where it wants your window placed.) NULL is not allowed if you are using 208 // aura. 209 gfx::NativeView context; 210 }; 211 212 Widget(); 213 virtual ~Widget(); 214 215 // Creates a toplevel window with no context. These methods should only be 216 // used in cases where there is no contextual information because we're 217 // creating a toplevel window connected to no other event. 218 // 219 // If you have any parenting or context information, or can pass that 220 // information, prefer the WithParent or WithContext versions of these 221 // methods. 222 static Widget* CreateWindow(WidgetDelegate* delegate); 223 static Widget* CreateWindowWithBounds(WidgetDelegate* delegate, 224 const gfx::Rect& bounds); 225 226 // Creates a decorated window Widget with the specified properties. 227 static Widget* CreateWindowWithParent(WidgetDelegate* delegate, 228 gfx::NativeWindow parent); 229 static Widget* CreateWindowWithParentAndBounds(WidgetDelegate* delegate, 230 gfx::NativeWindow parent, 231 const gfx::Rect& bounds); 232 233 // Creates a decorated window Widget in the same desktop context as 234 // |context|. 235 static Widget* CreateWindowWithContext(WidgetDelegate* delegate, 236 gfx::NativeView context); 237 static Widget* CreateWindowWithContextAndBounds(WidgetDelegate* delegate, 238 gfx::NativeView context, 239 const gfx::Rect& bounds); 240 241 242 // Enumerates all windows pertaining to us and notifies their 243 // view hierarchies that the locale has changed. 244 // TODO(beng): remove post-Aurafication of ChromeOS. 245 static void NotifyLocaleChanged(); 246 247 // Closes all Widgets that aren't identified as "secondary widgets". Called 248 // during application shutdown when the last non-secondary widget is closed. 249 static void CloseAllSecondaryWidgets(); 250 251 // Converts a rectangle from one Widget's coordinate system to another's. 252 // Returns false if the conversion couldn't be made, because either these two 253 // Widgets do not have a common ancestor or they are not on the screen yet. 254 // The value of |*rect| won't be changed when false is returned. 255 static bool ConvertRect(const Widget* source, 256 const Widget* target, 257 gfx::Rect* rect); 258 259 // Retrieves the Widget implementation associated with the given 260 // NativeView or Window, or NULL if the supplied handle has no associated 261 // Widget. 262 static Widget* GetWidgetForNativeView(gfx::NativeView native_view); 263 static Widget* GetWidgetForNativeWindow(gfx::NativeWindow native_window); 264 265 // Retrieves the top level widget in a native view hierarchy 266 // starting at |native_view|. Top level widget is a widget with TYPE_WINDOW, 267 // TYPE_PANEL, TYPE_WINDOW_FRAMELESS, POPUP or MENU and has its own 268 // focus manager. This may be itself if the |native_view| is top level, 269 // or NULL if there is no toplevel in a native view hierarchy. 270 static Widget* GetTopLevelWidgetForNativeView(gfx::NativeView native_view); 271 272 // Returns all Widgets in |native_view|'s hierarchy, including itself if 273 // it is one. 274 static void GetAllChildWidgets(gfx::NativeView native_view, 275 Widgets* children); 276 277 // Re-parent a NativeView and notify all Widgets in |native_view|'s hierarchy 278 // of the change. 279 static void ReparentNativeView(gfx::NativeView native_view, 280 gfx::NativeView new_parent); 281 282 // Returns the preferred size of the contents view of this window based on 283 // its localized size data. The width in cols is held in a localized string 284 // resource identified by |col_resource_id|, the height in the same fashion. 285 // TODO(beng): This should eventually live somewhere else, probably closer to 286 // ClientView. 287 static int GetLocalizedContentsWidth(int col_resource_id); 288 static int GetLocalizedContentsHeight(int row_resource_id); 289 static gfx::Size GetLocalizedContentsSize(int col_resource_id, 290 int row_resource_id); 291 292 // Returns true if the specified type requires a NonClientView. 293 static bool RequiresNonClientView(InitParams::Type type); 294 295 void Init(const InitParams& params); 296 297 // Returns the gfx::NativeView associated with this Widget. 298 gfx::NativeView GetNativeView() const; 299 300 // Returns the gfx::NativeWindow associated with this Widget. This may return 301 // NULL on some platforms if the widget was created with a type other than 302 // TYPE_WINDOW or TYPE_PANEL. 303 gfx::NativeWindow GetNativeWindow() const; 304 305 // Add/remove observer. 306 void AddObserver(WidgetObserver* observer); 307 void RemoveObserver(WidgetObserver* observer); 308 bool HasObserver(WidgetObserver* observer); 309 310 // Returns the accelerator given a command id. Returns false if there is 311 // no accelerator associated with a given id, which is a common condition. 312 virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator); 313 314 // Forwarded from the RootView so that the widget can do any cleanup. 315 void ViewHierarchyChanged(const View::ViewHierarchyChangedDetails& details); 316 317 // Performs any necessary cleanup and forwards to RootView. 318 void NotifyNativeViewHierarchyChanged(bool attached, 319 gfx::NativeView native_view); 320 321 // Returns the top level widget in a hierarchy (see is_top_level() for 322 // the definition of top level widget.) Will return NULL if called 323 // before the widget is attached to the top level widget's hierarchy. 324 Widget* GetTopLevelWidget(); 325 const Widget* GetTopLevelWidget() const; 326 327 // Gets/Sets the WidgetDelegate. 328 WidgetDelegate* widget_delegate() const { return widget_delegate_; } 329 330 // Sets the specified view as the contents of this Widget. There can only 331 // be one contents view child of this Widget's RootView. This view is sized to 332 // fit the entire size of the RootView. The RootView takes ownership of this 333 // View, unless it is set as not being parent-owned. 334 void SetContentsView(View* view); 335 View* GetContentsView(); 336 337 // Returns the bounds of the Widget in screen coordinates. 338 gfx::Rect GetWindowBoundsInScreen() const; 339 340 // Returns the bounds of the Widget's client area in screen coordinates. 341 gfx::Rect GetClientAreaBoundsInScreen() const; 342 343 // Retrieves the restored bounds for the window. 344 gfx::Rect GetRestoredBounds() const; 345 346 // Sizes and/or places the widget to the specified bounds, size or position. 347 void SetBounds(const gfx::Rect& bounds); 348 void SetSize(const gfx::Size& size); 349 350 // Sizes the window to the specified size and centerizes it. 351 void CenterWindow(const gfx::Size& size); 352 353 // Like SetBounds(), but ensures the Widget is fully visible on screen, 354 // resizing and/or repositioning as necessary. This is only useful for 355 // non-child widgets. 356 void SetBoundsConstrained(const gfx::Rect& bounds); 357 358 // Sets whether animations that occur when visibility is changed are enabled. 359 // Default is true. 360 void SetVisibilityChangedAnimationsEnabled(bool value); 361 362 // Starts a nested message loop that moves the window. This can be used to 363 // start a window move operation from a mouse or touch event. This returns 364 // when the move completes. |drag_offset| is the offset from the top left 365 // corner of the window to the point where the cursor is dragging, and is used 366 // to offset the bounds of the window from the cursor. 367 MoveLoopResult RunMoveLoop(const gfx::Vector2d& drag_offset, 368 MoveLoopSource source); 369 370 // Stops a previously started move loop. This is not immediate. 371 void EndMoveLoop(); 372 373 // Places the widget in front of the specified widget in z-order. 374 void StackAboveWidget(Widget* widget); 375 void StackAbove(gfx::NativeView native_view); 376 void StackAtTop(); 377 378 // Places the widget below the specified NativeView. 379 void StackBelow(gfx::NativeView native_view); 380 381 // Sets a shape on the widget. This takes ownership of shape. 382 void SetShape(gfx::NativeRegion shape); 383 384 // Hides the widget then closes it after a return to the message loop. 385 virtual void Close(); 386 387 // TODO(beng): Move off public API. 388 // Closes the widget immediately. Compare to |Close|. This will destroy the 389 // window handle associated with this Widget, so should not be called from 390 // any code that expects it to be valid beyond this call. 391 void CloseNow(); 392 393 // Shows or hides the widget, without changing activation state. 394 virtual void Show(); 395 void Hide(); 396 397 // Like Show(), but does not activate the window. 398 void ShowInactive(); 399 400 // Activates the widget, assuming it already exists and is visible. 401 void Activate(); 402 403 // Deactivates the widget, making the next window in the Z order the active 404 // window. 405 void Deactivate(); 406 407 // Returns whether the Widget is the currently active window. 408 virtual bool IsActive() const; 409 410 // Prevents the window from being rendered as deactivated. This state is 411 // reset automatically as soon as the window becomes activated again. There is 412 // no ability to control the state through this API as this leads to sync 413 // problems. 414 void DisableInactiveRendering(); 415 416 // Sets the widget to be on top of all other widgets in the windowing system. 417 void SetAlwaysOnTop(bool on_top); 418 419 // Maximizes/minimizes/restores the window. 420 void Maximize(); 421 void Minimize(); 422 void Restore(); 423 424 // Whether or not the window is maximized or minimized. 425 virtual bool IsMaximized() const; 426 bool IsMinimized() const; 427 428 // Accessors for fullscreen state. 429 void SetFullscreen(bool fullscreen); 430 bool IsFullscreen() const; 431 432 // Sets the opacity of the widget. This may allow widgets behind the widget 433 // in the Z-order to become visible, depending on the capabilities of the 434 // underlying windowing system. 435 void SetOpacity(unsigned char opacity); 436 437 // Sets whether or not the window should show its frame as a "transient drag 438 // frame" - slightly transparent and without the standard window controls. 439 void SetUseDragFrame(bool use_drag_frame); 440 441 // Flashes the frame of the window to draw attention to it. Currently only 442 // implemented on Windows for non-Aura. 443 void FlashFrame(bool flash); 444 445 // Returns the View at the root of the View hierarchy contained by this 446 // Widget. 447 View* GetRootView(); 448 const View* GetRootView() const; 449 450 // A secondary widget is one that is automatically closed (via Close()) when 451 // all non-secondary widgets are closed. 452 // Default is true. 453 // TODO(beng): This is an ugly API, should be handled implicitly via 454 // transience. 455 void set_is_secondary_widget(bool is_secondary_widget) { 456 is_secondary_widget_ = is_secondary_widget; 457 } 458 bool is_secondary_widget() const { return is_secondary_widget_; } 459 460 // Returns whether the Widget is visible to the user. 461 virtual bool IsVisible() const; 462 463 // Returns the ThemeProvider that provides theme resources for this Widget. 464 virtual ui::ThemeProvider* GetThemeProvider() const; 465 466 ui::NativeTheme* GetNativeTheme() { 467 return const_cast<ui::NativeTheme*>( 468 const_cast<const Widget*>(this)->GetNativeTheme()); 469 } 470 const ui::NativeTheme* GetNativeTheme() const; 471 472 // Returns the FocusManager for this widget. 473 // Note that all widgets in a widget hierarchy share the same focus manager. 474 FocusManager* GetFocusManager(); 475 const FocusManager* GetFocusManager() const; 476 477 // Returns the InputMethod for this widget. 478 // Note that all widgets in a widget hierarchy share the same input method. 479 InputMethod* GetInputMethod(); 480 481 // Starts a drag operation for the specified view. This blocks until the drag 482 // operation completes. |view| can be NULL. 483 // If the view is non-NULL it can be accessed during the drag by calling 484 // dragged_view(). If the view has not been deleted during the drag, 485 // OnDragDone() is called on it. |location| is in the widget's coordinate 486 // system. 487 void RunShellDrag(View* view, 488 const ui::OSExchangeData& data, 489 const gfx::Point& location, 490 int operation, 491 ui::DragDropTypes::DragEventSource source); 492 493 // Returns the view that requested the current drag operation via 494 // RunShellDrag(), or NULL if there is no such view or drag operation. 495 View* dragged_view() { return dragged_view_; } 496 497 // Adds the specified |rect| in client area coordinates to the rectangle to be 498 // redrawn. 499 void SchedulePaintInRect(const gfx::Rect& rect); 500 501 // Sets the currently visible cursor. If |cursor| is NULL, the cursor used 502 // before the current is restored. 503 void SetCursor(gfx::NativeCursor cursor); 504 505 // Sets/Gets a native window property on the underlying native window object. 506 // Returns NULL if the property does not exist. Setting the property value to 507 // NULL removes the property. 508 void SetNativeWindowProperty(const char* name, void* value); 509 void* GetNativeWindowProperty(const char* name) const; 510 511 // Tell the window to update its title from the delegate. 512 void UpdateWindowTitle(); 513 514 // Tell the window to update its icon from the delegate. 515 void UpdateWindowIcon(); 516 517 // Retrieves the focus traversable for this widget. 518 FocusTraversable* GetFocusTraversable(); 519 520 // Notifies the view hierarchy contained in this widget that theme resources 521 // changed. 522 void ThemeChanged(); 523 524 // Notifies the view hierarchy contained in this widget that locale resources 525 // changed. 526 void LocaleChanged(); 527 528 void SetFocusTraversableParent(FocusTraversable* parent); 529 void SetFocusTraversableParentView(View* parent_view); 530 531 // Clear native focus set to the Widget's NativeWidget. 532 void ClearNativeFocus(); 533 534 void set_frame_type(FrameType frame_type) { frame_type_ = frame_type; } 535 FrameType frame_type() const { return frame_type_; } 536 537 // Creates an appropriate NonClientFrameView for this widget. The 538 // WidgetDelegate is given the first opportunity to create one, followed by 539 // the NativeWidget implementation. If both return NULL, a default one is 540 // created. 541 virtual NonClientFrameView* CreateNonClientFrameView(); 542 543 // Whether we should be using a native frame. 544 bool ShouldUseNativeFrame() const; 545 546 // Forces the frame into the alternate frame type (custom or native) depending 547 // on its current state. 548 void DebugToggleFrameType(); 549 550 // Tell the window that something caused the frame type to change. 551 void FrameTypeChanged(); 552 553 NonClientView* non_client_view() { 554 return const_cast<NonClientView*>( 555 const_cast<const Widget*>(this)->non_client_view()); 556 } 557 const NonClientView* non_client_view() const { 558 return non_client_view_; 559 } 560 561 ClientView* client_view() { 562 return const_cast<ClientView*>( 563 const_cast<const Widget*>(this)->client_view()); 564 } 565 const ClientView* client_view() const { 566 // non_client_view_ may be NULL, especially during creation. 567 return non_client_view_ ? non_client_view_->client_view() : NULL; 568 } 569 570 const ui::Compositor* GetCompositor() const; 571 ui::Compositor* GetCompositor(); 572 573 // Returns the widget's layer, if any. 574 ui::Layer* GetLayer(); 575 576 // Schedules an update to the root layers. The actual processing occurs when 577 // GetRootLayers() is invoked. 578 void UpdateRootLayers(); 579 580 const NativeWidget* native_widget() const; 581 NativeWidget* native_widget(); 582 583 internal::NativeWidgetPrivate* native_widget_private() { 584 return native_widget_; 585 } 586 const internal::NativeWidgetPrivate* native_widget_private() const { 587 return native_widget_; 588 } 589 590 // Sets capture to the specified view. This makes it so that all mouse, touch 591 // and gesture events go to |view|. 592 void SetCapture(View* view); 593 594 // Releases capture. 595 void ReleaseCapture(); 596 597 // Returns true if the widget has capture. 598 bool HasCapture(); 599 600 // Returns the current event being processed. If there are multiple events 601 // being processed at the same time (e.g. one event triggers another event), 602 // then the most recent event is returned. Returns NULL if no event is being 603 // processed. 604 const ui::Event* GetCurrentEvent(); 605 606 // Invoked when the tooltip text changes for the specified views. 607 void TooltipTextChanged(View* view); 608 609 // Sets-up the focus manager with the view that should have focus when the 610 // window is shown the first time. Returns true if the initial focus has been 611 // set or the widget should not set the initial focus, or false if the caller 612 // should set the initial focus (if any). 613 bool SetInitialFocus(); 614 615 void set_focus_on_creation(bool focus_on_creation) { 616 focus_on_creation_ = focus_on_creation; 617 } 618 619 // Returns a View* that any child Widgets backed by NativeWidgetViews 620 // are added to. The default implementation returns the contents view 621 // if it exists and the root view otherwise. 622 virtual View* GetChildViewParent(); 623 624 // True if the widget is considered top level widget. Top level widget 625 // is a widget of TYPE_WINDOW, TYPE_PANEL, TYPE_WINDOW_FRAMELESS, BUBBLE, 626 // POPUP or MENU, and has a focus manager and input method object associated 627 // with it. TYPE_CONTROL and TYPE_TOOLTIP is not considered top level. 628 bool is_top_level() const { return is_top_level_; } 629 630 // True when window movement via mouse interaction with the frame is disabled. 631 bool movement_disabled() const { return movement_disabled_; } 632 void set_movement_disabled(bool disabled) { movement_disabled_ = disabled; } 633 634 // Returns the work area bounds of the screen the Widget belongs to. 635 gfx::Rect GetWorkAreaBoundsInScreen() const; 636 637 // Creates and dispatches synthesized mouse move event using the current 638 // mouse location to refresh hovering status in the widget. 639 void SynthesizeMouseMoveEvent(); 640 641 // Notification that our owner is closing. 642 // NOTE: this is not invoked for aura as it's currently not needed there. 643 // Under aura menus close by way of activation getting reset when the owner 644 // closes. 645 virtual void OnOwnerClosing(); 646 647 // Overridden from NativeWidgetDelegate: 648 virtual bool IsModal() const OVERRIDE; 649 virtual bool IsDialogBox() const OVERRIDE; 650 virtual bool CanActivate() const OVERRIDE; 651 virtual bool IsInactiveRenderingDisabled() const OVERRIDE; 652 virtual void EnableInactiveRendering() OVERRIDE; 653 virtual void OnNativeWidgetActivationChanged(bool active) OVERRIDE; 654 virtual void OnNativeFocus(gfx::NativeView old_focused_view) OVERRIDE; 655 virtual void OnNativeBlur(gfx::NativeView new_focused_view) OVERRIDE; 656 virtual void OnNativeWidgetVisibilityChanged(bool visible) OVERRIDE; 657 virtual void OnNativeWidgetCreated() OVERRIDE; 658 virtual void OnNativeWidgetDestroying() OVERRIDE; 659 virtual void OnNativeWidgetDestroyed() OVERRIDE; 660 virtual gfx::Size GetMinimumSize() OVERRIDE; 661 virtual gfx::Size GetMaximumSize() OVERRIDE; 662 virtual void OnNativeWidgetMove() OVERRIDE; 663 virtual void OnNativeWidgetSizeChanged(const gfx::Size& new_size) OVERRIDE; 664 virtual void OnNativeWidgetBeginUserBoundsChange() OVERRIDE; 665 virtual void OnNativeWidgetEndUserBoundsChange() OVERRIDE; 666 virtual bool HasFocusManager() const OVERRIDE; 667 virtual bool OnNativeWidgetPaintAccelerated( 668 const gfx::Rect& dirty_region) OVERRIDE; 669 virtual void OnNativeWidgetPaint(gfx::Canvas* canvas) OVERRIDE; 670 virtual int GetNonClientComponent(const gfx::Point& point) OVERRIDE; 671 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; 672 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 673 virtual void OnMouseCaptureLost() OVERRIDE; 674 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; 675 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; 676 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 677 virtual bool ExecuteCommand(int command_id) OVERRIDE; 678 virtual InputMethod* GetInputMethodDirect() OVERRIDE; 679 virtual const std::vector<ui::Layer*>& GetRootLayers() OVERRIDE; 680 virtual bool HasHitTestMask() const OVERRIDE; 681 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE; 682 virtual Widget* AsWidget() OVERRIDE; 683 virtual const Widget* AsWidget() const OVERRIDE; 684 685 // Overridden from FocusTraversable: 686 virtual FocusSearch* GetFocusSearch() OVERRIDE; 687 virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE; 688 virtual View* GetFocusTraversableParentView() OVERRIDE; 689 690 protected: 691 // Creates the RootView to be used within this Widget. Subclasses may override 692 // to create custom RootViews that do specialized event processing. 693 // TODO(beng): Investigate whether or not this is needed. 694 virtual internal::RootView* CreateRootView(); 695 696 // Provided to allow the NativeWidget implementations to destroy the RootView 697 // _before_ the focus manager/tooltip manager. 698 // TODO(beng): remove once we fold those objects onto this one. 699 void DestroyRootView(); 700 701 private: 702 friend class NativeTextfieldViewsTest; 703 friend class NativeComboboxViewsTest; 704 friend class ScopedEvent; 705 706 // Returns whether capture should be released on mouse release. 707 virtual bool ShouldReleaseCaptureOnMouseReleased() const; 708 709 // Sets the value of |disable_inactive_rendering_|. If the value changes, 710 // both the NonClientView and WidgetDelegate are notified. 711 void SetInactiveRenderingDisabled(bool value); 712 713 // Persists the window's restored position and "show" state using the 714 // window delegate. 715 void SaveWindowPlacement(); 716 717 // Sizes and positions the window just after it is created. 718 void SetInitialBounds(const gfx::Rect& bounds); 719 720 // Sizes and positions the frameless window just after it is created. 721 void SetInitialBoundsForFramelessWindow(const gfx::Rect& bounds); 722 723 // Returns the bounds and "show" state from the delegate. Returns true if 724 // the delegate wants to use a specified bounds. 725 bool GetSavedWindowPlacement(gfx::Rect* bounds, 726 ui::WindowShowState* show_state); 727 728 // Sets a different InputMethod instance to this widget. The instance 729 // must not be initialized, the ownership will be assumed by the widget. 730 // It's only for testing purpose. 731 void ReplaceInputMethod(InputMethod* input_method); 732 733 internal::NativeWidgetPrivate* native_widget_; 734 735 ObserverList<WidgetObserver> observers_; 736 737 // Non-owned pointer to the Widget's delegate. May be NULL if no delegate is 738 // being used. 739 WidgetDelegate* widget_delegate_; 740 741 // The root of the View hierarchy attached to this window. 742 // WARNING: see warning in tooltip_manager_ for ordering dependencies with 743 // this and tooltip_manager_. 744 scoped_ptr<internal::RootView> root_view_; 745 746 // The View that provides the non-client area of the window (title bar, 747 // window controls, sizing borders etc). To use an implementation other than 748 // the default, this class must be sub-classed and this value set to the 749 // desired implementation before calling |InitWindow()|. 750 NonClientView* non_client_view_; 751 752 // The focus manager keeping track of focus for this Widget and any of its 753 // children. NULL for non top-level widgets. 754 // WARNING: RootView's destructor calls into the FocusManager. As such, this 755 // must be destroyed AFTER root_view_. This is enforced in DestroyRootView(). 756 scoped_ptr<FocusManager> focus_manager_; 757 758 // A theme provider to use when no other theme provider is specified. 759 scoped_ptr<ui::DefaultThemeProvider> default_theme_provider_; 760 761 // Valid for the lifetime of RunShellDrag(), indicates the view the drag 762 // started from. 763 View* dragged_view_; 764 765 // The event stack. 766 std::stack<ScopedEvent*> event_stack_; 767 768 // See class documentation for Widget above for a note about ownership. 769 InitParams::Ownership ownership_; 770 771 // See set_is_secondary_widget(). 772 bool is_secondary_widget_; 773 774 // The current frame type in use by this window. Defaults to 775 // FRAME_TYPE_DEFAULT. 776 FrameType frame_type_; 777 778 // True when the window should be rendered as active, regardless of whether 779 // or not it actually is. 780 bool disable_inactive_rendering_; 781 782 // Set to true if the widget is in the process of closing. 783 bool widget_closed_; 784 785 // The saved "show" state for this window. See note in SetInitialBounds 786 // that explains why we save this. 787 ui::WindowShowState saved_show_state_; 788 789 // The restored bounds used for the initial show. This is only used if 790 // |saved_show_state_| is maximized. 791 gfx::Rect initial_restored_bounds_; 792 793 // Focus is automatically set to the view provided by the delegate 794 // when the widget is shown. Set this value to false to override 795 // initial focus for the widget. 796 bool focus_on_creation_; 797 798 scoped_ptr<InputMethod> input_method_; 799 800 // See |is_top_level()| accessor. 801 bool is_top_level_; 802 803 // Tracks whether native widget has been initialized. 804 bool native_widget_initialized_; 805 806 // Whether native widget has been destroyed. 807 bool native_widget_destroyed_; 808 809 // TODO(beng): Remove NativeWidgetGtk's dependence on these: 810 // If true, the mouse is currently down. 811 bool is_mouse_button_pressed_; 812 813 // If true, a touch device is currently down. 814 bool is_touch_down_; 815 816 // TODO(beng): Remove NativeWidgetGtk's dependence on these: 817 // The following are used to detect duplicate mouse move events and not 818 // deliver them. Displaying a window may result in the system generating 819 // duplicate move events even though the mouse hasn't moved. 820 bool last_mouse_event_was_move_; 821 gfx::Point last_mouse_event_position_; 822 823 // See description in GetRootLayers(). 824 std::vector<ui::Layer*> root_layers_; 825 826 // Is |root_layers_| out of date? 827 bool root_layers_dirty_; 828 829 // True when window movement via mouse interaction with the frame should be 830 // disabled. 831 bool movement_disabled_; 832 833 DISALLOW_COPY_AND_ASSIGN(Widget); 834}; 835 836} // namespace views 837 838#endif // UI_VIEWS_WIDGET_WIDGET_H_ 839