#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
+#include "base/scoped_observer.h"
#include "ui/aura/window_layer_type.h"
#include "ui/base/ui_base_types.h"
+#include "ui/events/event_source.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/rect.h"
+#include "ui/native_theme/native_theme_observer.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/widget/native_widget_delegate.h"
#include "ui/views/window/client_view.h"
class Accelerator;
class Compositor;
class DefaultThemeProvider;
+class InputMethod;
class Layer;
class NativeTheme;
class OSExchangeData;
class View;
class WidgetDelegate;
class WidgetObserver;
+class WidgetRemovalsObserver;
namespace internal {
class NativeWidgetPrivate;
// destructor).
//
class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
- public FocusTraversable {
+ public ui::EventSource,
+ public FocusTraversable,
+ public ui::NativeThemeObserver {
public:
typedef std::set<Widget*> Widgets;
TRANSLUCENT_WINDOW,
};
+ enum Activatable {
+ // Infer whether the window should be activatable from the window type.
+ ACTIVATABLE_DEFAULT,
+
+ ACTIVATABLE_YES,
+ ACTIVATABLE_NO
+ };
+
enum Ownership {
// Default. Creator is not responsible for managing the lifetime of the
// Widget, it is destroyed when the corresponding NativeWidget is
WIDGET_OWNS_NATIVE_WIDGET
};
+ enum ShadowType {
+ SHADOW_TYPE_DEFAULT, // Use default shadow setting. It will be one of
+ // the settings below depending on InitParams::type
+ // and the native widget's type.
+ SHADOW_TYPE_NONE, // Don't draw any shadow.
+ SHADOW_TYPE_DROP, // Draw a drop shadow that emphasizes Z-order
+ // relationship to other windows.
+ };
+
InitParams();
explicit InitParams(Type type);
~InitParams();
WidgetDelegate* delegate;
bool child;
// If TRANSLUCENT_WINDOW, the widget may be fully or partially transparent.
+ // Translucent windows may not always be supported. Use
+ // IsTranslucentWindowOpacitySupported to determine if translucent windows
+ // are supported.
// If OPAQUE_WINDOW, we can perform optimizations based on the widget being
// fully opaque. Defaults to TRANSLUCENT_WINDOW if
// ViewsDelegate::UseTransparentWindows(). Defaults to OPAQUE_WINDOW for
// non-window widgets.
WindowOpacity opacity;
bool accept_events;
- bool can_activate;
+ Activatable activatable;
bool keep_on_top;
+ bool visible_on_all_workspaces;
Ownership ownership;
bool mirror_origin_in_rtl;
- bool has_dropshadow;
+ ShadowType shadow_type;
// Specifies that the system default caption and icon should not be
// rendered, and that the client area should be equivalent to the window
// area. Only used on some platforms (Windows and Linux).
// of the default one.
// TODO(beng): Figure out if there's a better way to expose this, e.g. get
// rid of NW subclasses and do this all via message handling.
- DesktopWindowTreeHost* desktop_root_window_host;
- // Whether this window is intended to be a toplevel window with no
- // attachment to any other window. (This may be a transient window if
- // |parent| is set.)
- bool top_level;
+ DesktopWindowTreeHost* desktop_window_tree_host;
// Only used by NativeWidgetAura. Specifies the type of layer for the
// aura::Window. Default is WINDOW_LAYER_TEXTURED.
aura::WindowLayerType layer_type;
// |parent|. If you pass a RootWindow to |context|, we ask that RootWindow
// where it wants your window placed.) NULL is not allowed if you are using
// aura.
- gfx::NativeView context;
+ gfx::NativeWindow context;
// If true, forces the window to be shown in the taskbar, even for window
// types that do not appear in the taskbar by default (popup and bubble).
bool force_show_in_taskbar;
// Creates a decorated window Widget with the specified properties.
static Widget* CreateWindowWithParent(WidgetDelegate* delegate,
- gfx::NativeWindow parent);
+ gfx::NativeView parent);
static Widget* CreateWindowWithParentAndBounds(WidgetDelegate* delegate,
- gfx::NativeWindow parent,
+ gfx::NativeView parent,
const gfx::Rect& bounds);
// Creates a decorated window Widget in the same desktop context as |context|.
static Widget* CreateWindowWithContext(WidgetDelegate* delegate,
- gfx::NativeView context);
+ gfx::NativeWindow context);
static Widget* CreateWindowWithContextAndBounds(WidgetDelegate* delegate,
- gfx::NativeView context,
+ gfx::NativeWindow context,
const gfx::Rect& bounds);
- // Creates an undecorated child window Widget parented to |parent|.
- static Widget* CreateWindowAsFramelessChild(WidgetDelegate* widget_delegate,
- gfx::NativeView parent);
-
// Closes all Widgets that aren't identified as "secondary widgets". Called
// during application shutdown when the last non-secondary widget is closed.
static void CloseAllSecondaryWidgets();
void RemoveObserver(WidgetObserver* observer);
bool HasObserver(WidgetObserver* observer);
+ // Add/remove removals observer.
+ void AddRemovalsObserver(WidgetRemovalsObserver* observer);
+ void RemoveRemovalsObserver(WidgetRemovalsObserver* observer);
+ bool HasRemovalsObserver(WidgetRemovalsObserver* observer);
+
// Returns the accelerator given a command id. Returns false if there is
// no accelerator associated with a given id, which is a common condition.
- virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator);
+ virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator) const;
// Forwarded from the RootView so that the widget can do any cleanup.
void ViewHierarchyChanged(const View::ViewHierarchyChangedDetails& details);
// about the change.
void NotifyNativeViewHierarchyChanged();
+ // Called immediately before removing |view| from this widget.
+ void NotifyWillRemoveView(View* view);
+
// Returns the top level widget in a hierarchy (see is_top_level() for
// the definition of top level widget.) Will return NULL if called
// before the widget is attached to the top level widget's hierarchy.
// in the windowing system.
bool IsAlwaysOnTop() const;
+ // Sets the widget to be visible on all work spaces.
+ void SetVisibleOnAllWorkspaces(bool always_visible);
+
// Maximizes/minimizes/restores the window.
void Maximize();
void Minimize();
InputMethod* GetInputMethod();
const InputMethod* GetInputMethod() const;
+ // Returns the ui::InputMethod for this widget.
+ // TODO(yukishiino): Rename this method to GetInputMethod once we remove
+ // views::InputMethod.
+ ui::InputMethod* GetHostInputMethod();
+
// Starts a drag operation for the specified view. This blocks until the drag
// operation completes. |view| can be NULL.
// If the view is non-NULL it can be accessed during the drag by calling
// Whether we should be using a native frame.
bool ShouldUseNativeFrame() const;
+ // Determines whether the window contents should be rendered transparently
+ // (for example, so that they can overhang onto the window title bar).
+ bool ShouldWindowContentsBeTransparent() const;
+
// Forces the frame into the alternate frame type (custom or native) depending
// on its current state.
void DebugToggleFrameType();
// window sizing information to the window server on some platforms.
void OnRootViewLayout();
+ // Whether the widget supports translucency.
+ bool IsTranslucentWindowOpacitySupported() const;
+
// Notification that our owner is closing.
// NOTE: this is not invoked for aura as it's currently not needed there.
// Under aura menus close by way of activation getting reset when the owner
virtual void OnNativeWidgetCreated(bool desktop_widget) OVERRIDE;
virtual void OnNativeWidgetDestroying() OVERRIDE;
virtual void OnNativeWidgetDestroyed() OVERRIDE;
- virtual gfx::Size GetMinimumSize() OVERRIDE;
- virtual gfx::Size GetMaximumSize() OVERRIDE;
+ virtual gfx::Size GetMinimumSize() const OVERRIDE;
+ virtual gfx::Size GetMaximumSize() const OVERRIDE;
virtual void OnNativeWidgetMove() OVERRIDE;
virtual void OnNativeWidgetSizeChanged(const gfx::Size& new_size) OVERRIDE;
+ virtual void OnNativeWidgetWindowShowStateChanged() OVERRIDE;
virtual void OnNativeWidgetBeginUserBoundsChange() OVERRIDE;
virtual void OnNativeWidgetEndUserBoundsChange() OVERRIDE;
virtual bool HasFocusManager() const OVERRIDE;
virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
virtual void OnMouseCaptureLost() OVERRIDE;
- virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
virtual bool ExecuteCommand(int command_id) OVERRIDE;
virtual const Widget* AsWidget() const OVERRIDE;
virtual bool SetInitialFocus(ui::WindowShowState show_state) OVERRIDE;
+ // Overridden from ui::EventSource:
+ virtual ui::EventProcessor* GetEventProcessor() OVERRIDE;
+
// Overridden from FocusTraversable:
virtual FocusSearch* GetFocusSearch() OVERRIDE;
virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE;
virtual View* GetFocusTraversableParentView() OVERRIDE;
+ // Overridden from ui::NativeThemeObserver:
+ virtual void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) OVERRIDE;
+
protected:
// Creates the RootView to be used within this Widget. Subclasses may override
// to create custom RootViews that do specialized event processing.
// TODO(beng): remove once we fold those objects onto this one.
void DestroyRootView();
+ // Notification that a drag will start. Default implementation does nothing.
+ virtual void OnDragWillStart();
+
+ // Notification that the drag performed by RunShellDrag() has completed.
+ virtual void OnDragComplete();
+
private:
friend class ComboboxTest;
friend class TextfieldTest;
// window delegate.
void SaveWindowPlacement();
+ // Invokes SaveWindowPlacement() if the native widget has been initialized.
+ // This is called at times when the native widget may not have been
+ // initialized.
+ void SaveWindowPlacementIfInitialized();
+
// Sizes and positions the window just after it is created.
void SetInitialBounds(const gfx::Rect& bounds);
ObserverList<WidgetObserver> observers_;
+ ObserverList<WidgetRemovalsObserver> removals_observers_;
+
// Non-owned pointer to the Widget's delegate. If a NULL delegate is supplied
// to Init() a default WidgetDelegate is created.
WidgetDelegate* widget_delegate_;
// If true, the mouse is currently down.
bool is_mouse_button_pressed_;
- // If true, a touch device is currently down.
- bool is_touch_down_;
+ // True if capture losses should be ignored.
+ bool ignore_capture_loss_;
// TODO(beng): Remove NativeWidgetGtk's dependence on these:
// The following are used to detect duplicate mouse move events and not
// disabled.
bool movement_disabled_;
+ ScopedObserver<ui::NativeTheme, ui::NativeThemeObserver> observer_manager_;
+
DISALLOW_COPY_AND_ASSIGN(Widget);
};