1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_WIDGET_NATIVE_WIDGET_DELEGATE_H_
6 #define UI_VIEWS_WIDGET_NATIVE_WIDGET_DELEGATE_H_
10 #include "ui/events/event_constants.h"
11 #include "ui/views/views_export.h"
36 ////////////////////////////////////////////////////////////////////////////////
37 // NativeWidgetDelegate
39 // An interface implemented by the object that handles events sent by a
40 // NativeWidget implementation.
42 class VIEWS_EXPORT NativeWidgetDelegate
{
44 virtual ~NativeWidgetDelegate() {}
46 // Returns true if the window is modal.
47 virtual bool IsModal() const = 0;
49 // Returns true if the window is a dialog box.
50 virtual bool IsDialogBox() const = 0;
52 // Returns true if the window can be activated.
53 virtual bool CanActivate() const = 0;
55 virtual bool IsInactiveRenderingDisabled() const = 0;
56 virtual void EnableInactiveRendering() = 0;
58 // Called when the activation state of a window has changed.
59 virtual void OnNativeWidgetActivationChanged(bool active
) = 0;
61 // Called when native focus moves from one native view to another.
62 virtual void OnNativeFocus() = 0;
63 virtual void OnNativeBlur() = 0;
65 // Called when the window is about to be shown/hidden.
66 virtual void OnNativeWidgetVisibilityChanging(bool visible
) = 0;
68 // Called when the window is shown/hidden.
69 virtual void OnNativeWidgetVisibilityChanged(bool visible
) = 0;
71 // Called when the native widget is created.
72 // The |desktop_widget| bool is true for widgets created in the desktop and
73 // false for widgets created in the shell.
74 virtual void OnNativeWidgetCreated(bool desktop_widget
) = 0;
76 // Called just before the native widget is destroyed. This is the delegate's
77 // last chance to do anything with the native widget handle.
78 virtual void OnNativeWidgetDestroying() = 0;
80 // Called just after the native widget is destroyed.
81 virtual void OnNativeWidgetDestroyed() = 0;
83 // Returns the smallest size the window can be resized to by the user.
84 virtual gfx::Size
GetMinimumSize() const = 0;
86 // Returns the largest size the window can be resized to by the user.
87 virtual gfx::Size
GetMaximumSize() const = 0;
89 // Called when the NativeWidget changed position.
90 virtual void OnNativeWidgetMove() = 0;
92 // Called when the NativeWidget changed size to |new_size|.
93 // This may happen at the same time as OnNativeWidgetWindowShowStateChanged,
95 virtual void OnNativeWidgetSizeChanged(const gfx::Size
& new_size
) = 0;
97 // Called when the NativeWidget changes its window state.
98 // This may happen at the same time as OnNativeWidgetSizeChanged, e.g.
100 virtual void OnNativeWidgetWindowShowStateChanged() = 0;
102 // Called when the user begins/ends to change the bounds of the window.
103 virtual void OnNativeWidgetBeginUserBoundsChange() = 0;
104 virtual void OnNativeWidgetEndUserBoundsChange() = 0;
106 // Returns true if the delegate has a FocusManager.
107 virtual bool HasFocusManager() const = 0;
109 // Paints the widget using acceleration. If the widget is not using
110 // accelerated painting this returns false and does nothing.
111 virtual bool OnNativeWidgetPaintAccelerated(
112 const gfx::Rect
& dirty_region
) = 0;
114 // Paints the rootview in the context. This will also refresh the compositor
115 // tree if necessary.
116 virtual void OnNativeWidgetPaint(const ui::PaintContext
& context
) = 0;
118 // Returns the non-client component (see ui/base/hit_test.h) containing
119 // |point|, in client coordinates.
120 virtual int GetNonClientComponent(const gfx::Point
& point
) = 0;
122 // Mouse and key event handlers.
123 virtual void OnKeyEvent(ui::KeyEvent
* event
) = 0;
124 virtual void OnMouseEvent(ui::MouseEvent
* event
) = 0;
125 virtual void OnMouseCaptureLost() = 0;
127 virtual void OnScrollEvent(ui::ScrollEvent
* event
) = 0;
128 virtual void OnGestureEvent(ui::GestureEvent
* event
) = 0;
130 // Runs the specified native command. Returns true if the command is handled.
131 virtual bool ExecuteCommand(int command_id
) = 0;
133 // Returns the input method of the widget this delegate is associated with.
134 // Note that this does not use the top level widget, so may return NULL
135 // if the widget doesn't have input method.
136 virtual InputMethod
* GetInputMethodDirect() = 0;
138 // Returns the child Layers of the Widgets layer that were created by Views.
139 virtual const std::vector
<ui::Layer
*>& GetRootLayers() = 0;
141 // Returns true if window has a hit-test mask.
142 virtual bool HasHitTestMask() const = 0;
144 // Provides the hit-test mask if HasHitTestMask above returns true.
145 virtual void GetHitTestMask(gfx::Path
* mask
) const = 0;
148 virtual Widget
* AsWidget() = 0;
149 virtual const Widget
* AsWidget() const = 0;
151 // Sets-up the focus manager with the view that should have focus when the
152 // window is shown the first time. It takes the intended |show_state| of the
153 // window in order to decide whether the window should be focused now or
154 // later. Returns true if the initial focus has been set or the window should
155 // not set the initial focus, or false if the caller should set the initial
157 virtual bool SetInitialFocus(ui::WindowShowState show_state
) = 0;
160 } // namespace internal
163 #endif // UI_VIEWS_WIDGET_NATIVE_WIDGET_DELEGATE_H_