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_WIN_HWND_MESSAGE_HANDLER_DELEGATE_H_ 6 #define UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_DELEGATE_H_ 7 8 #include "ui/views/views_export.h" 9 10 namespace gfx { 11 class Canvas; 12 class Insets; 13 class Path; 14 class Point; 15 class Size; 16 } 17 18 namespace ui { 19 class Accelerator; 20 class KeyEvent; 21 class MouseEvent; 22 class TouchEvent; 23 } 24 25 namespace views { 26 27 class InputMethod; 28 class NativeWidgetWin; 29 30 // Implemented by the object that uses the HWNDMessageHandler to handle 31 // notifications from the underlying HWND and service requests for data. 32 class VIEWS_EXPORT HWNDMessageHandlerDelegate { 33 public: 34 virtual bool IsWidgetWindow() const = 0; 35 36 // TODO(beng): resolve this more satisfactorily vis-a-vis ShouldUseNativeFrame 37 // to avoid confusion. 38 virtual bool IsUsingCustomFrame() const = 0; 39 40 virtual void SchedulePaint() = 0; 41 virtual void EnableInactiveRendering() = 0; 42 virtual bool IsInactiveRenderingDisabled() = 0; 43 44 virtual bool CanResize() const = 0; 45 virtual bool CanMaximize() const = 0; 46 virtual bool CanActivate() const = 0; 47 48 virtual bool WidgetSizeIsClientSize() const = 0; 49 50 // Returns true if the delegate has a focus saving mechanism that should be 51 // used when the window is activated and deactivated. 52 virtual bool CanSaveFocus() const = 0; 53 virtual void SaveFocusOnDeactivate() = 0; 54 virtual void RestoreFocusOnActivate() = 0; 55 virtual void RestoreFocusOnEnable() = 0; 56 57 // Returns true if the delegate represents a modal window. 58 virtual bool IsModal() const = 0; 59 60 // Returns the show state that should be used for the application's first 61 // window. 62 virtual int GetInitialShowState() const = 0; 63 64 virtual bool WillProcessWorkAreaChange() const = 0; 65 66 virtual int GetNonClientComponent(const gfx::Point& point) const = 0; 67 virtual void GetWindowMask(const gfx::Size& size, gfx::Path* mask) = 0; 68 69 // Returns true if the delegate modifies |insets| to define a custom client 70 // area for the window, false if the default client area should be used. If 71 // false is returned, |insets| is not modified. 72 virtual bool GetClientAreaInsets(gfx::Insets* insets) const = 0; 73 74 // Returns the minimum and maximum size the window can be resized to by the 75 // user. 76 virtual void GetMinMaxSize(gfx::Size* min_size, 77 gfx::Size* max_size) const = 0; 78 79 // Returns the current size of the RootView. 80 virtual gfx::Size GetRootViewSize() const = 0; 81 82 virtual void ResetWindowControls() = 0; 83 84 virtual void PaintLayeredWindow(gfx::Canvas* canvas) = 0; 85 86 virtual InputMethod* GetInputMethod() = 0; 87 88 virtual gfx::NativeViewAccessible GetNativeViewAccessible() = 0; 89 90 // Returns true if the window should handle standard system commands, such as 91 // close, minimize, maximize. 92 // TODO(benwells): Remove this once bubbles don't have two widgets 93 // implementing them on non-aura windows. http://crbug.com/189112. 94 virtual bool ShouldHandleSystemCommands() const = 0; 95 96 // TODO(beng): Investigate migrating these methods to On* prefixes once 97 // HWNDMessageHandler is the WindowImpl. 98 99 // Called when another app was activated. 100 virtual void HandleAppDeactivated() = 0; 101 102 // Called when the window was activated or deactivated. |active| reflects the 103 // new state. 104 virtual void HandleActivationChanged(bool active) = 0; 105 106 // Called when a well known "app command" from the system was performed. 107 // Returns true if the command was handled. 108 virtual bool HandleAppCommand(short command) = 0; 109 110 // Called from WM_CANCELMODE. 111 virtual void HandleCancelMode() = 0; 112 113 // Called when the window has lost mouse capture. 114 virtual void HandleCaptureLost() = 0; 115 116 // Called when the user tried to close the window. 117 virtual void HandleClose() = 0; 118 119 // Called when a command defined by the application was performed. Returns 120 // true if the command was handled. 121 virtual bool HandleCommand(int command) = 0; 122 123 // Called when an accelerator is invoked. 124 virtual void HandleAccelerator(const ui::Accelerator& accelerator) = 0; 125 126 // Called when the HWND is created. 127 virtual void HandleCreate() = 0; 128 129 // Called when the HWND is being destroyed, before any child HWNDs are 130 // destroyed. 131 virtual void HandleDestroying() = 0; 132 133 // Called after the HWND is destroyed, after all child HWNDs have been 134 // destroyed. 135 virtual void HandleDestroyed() = 0; 136 137 // Called when the HWND is to be focused for the first time. This is called 138 // when the window is shown for the first time. Returns true if the delegate 139 // set focus and no default processing should be done by the message handler. 140 virtual bool HandleInitialFocus() = 0; 141 142 // Called when display settings are adjusted on the system. 143 virtual void HandleDisplayChange() = 0; 144 145 // Called when the user begins or ends a size/move operation using the window 146 // manager. 147 virtual void HandleBeginWMSizeMove() = 0; 148 virtual void HandleEndWMSizeMove() = 0; 149 150 // Called when the window's position changed. 151 virtual void HandleMove() = 0; 152 153 // Called when the system's work area has changed. 154 virtual void HandleWorkAreaChanged() = 0; 155 156 // Called when the window's visibility is changing. |visible| holds the new 157 // state. 158 virtual void HandleVisibilityChanging(bool visible) = 0; 159 160 // Called when the window's visibility changed. |visible| holds the new state. 161 virtual void HandleVisibilityChanged(bool visible) = 0; 162 163 // Called when the window's client size changed. |new_size| holds the new 164 // size. 165 virtual void HandleClientSizeChanged(const gfx::Size& new_size) = 0; 166 167 // Called when the window's frame has changed. 168 virtual void HandleFrameChanged() = 0; 169 170 // Called when focus shifted to this HWND from |last_focused_window|. 171 virtual void HandleNativeFocus(HWND last_focused_window) = 0; 172 173 // Called when focus shifted from the HWND to a different window. 174 virtual void HandleNativeBlur(HWND focused_window) = 0; 175 176 // Called when a mouse event is received. Returns true if the event was 177 // handled by the delegate. 178 virtual bool HandleMouseEvent(const ui::MouseEvent& event) = 0; 179 180 // Called when a translated key event is received (i.e. post IME translation.) 181 // Returns true if the event was handled by the delegate. 182 virtual bool HandleKeyEvent(const ui::KeyEvent& event) = 0; 183 184 // Called when an untranslated key event is received (i.e. pre-IME 185 // translation). Returns true if the event was sent to the input method. 186 virtual bool HandleUntranslatedKeyEvent(const ui::KeyEvent& event) = 0; 187 188 // Called when a touch event is received. 189 virtual void HandleTouchEvent(const ui::TouchEvent& event) = 0; 190 191 // Called when an IME message needs to be processed by the delegate. Returns 192 // true if the event was handled and no default processing should be 193 // performed. 194 virtual bool HandleIMEMessage(UINT message, 195 WPARAM w_param, 196 LPARAM l_param, 197 LRESULT* result) = 0; 198 199 // Called when the system input language changes. 200 virtual void HandleInputLanguageChange(DWORD character_set, 201 HKL input_language_id) = 0; 202 203 // Called to compel the delegate to paint |invalid_rect| accelerated. Returns 204 // true if accelerated painting was performed. 205 virtual bool HandlePaintAccelerated(const gfx::Rect& invalid_rect) = 0; 206 207 // Called to compel the delegate to paint using the software path. 208 virtual void HandlePaint(gfx::Canvas* canvas) = 0; 209 210 // Called to forward a WM_NOTIFY message to the tooltip manager. 211 virtual bool HandleTooltipNotify(int w_param, 212 NMHDR* l_param, 213 LRESULT* l_result) = 0; 214 215 // Called to forward mouse events to the tooltip manager. 216 virtual void HandleTooltipMouseMove(UINT message, 217 WPARAM w_param, 218 LPARAM l_param) = 0; 219 220 // Catch-all message handling and filtering. Called before 221 // HWNDMessageHandler's built-in handling, which may pre-empt some 222 // expectations in Views/Aura if messages are consumed. Returns true if the 223 // message was consumed by the delegate and should not be processed further 224 // by the HWNDMessageHandler. In this case, |result| is returned. |result| is 225 // not modified otherwise. 226 virtual bool PreHandleMSG(UINT message, 227 WPARAM w_param, 228 LPARAM l_param, 229 LRESULT* result) = 0; 230 231 // Like PreHandleMSG, but called after HWNDMessageHandler's built-in handling 232 // has run and after DefWindowProc. 233 virtual void PostHandleMSG(UINT message, 234 WPARAM w_param, 235 LPARAM l_param) = 0; 236 237 // Called when a scroll event is received. Returns true if the event was 238 // handled by the delegate. 239 virtual bool HandleScrollEvent(const ui::ScrollEvent& event) = 0; 240 241 protected: 242 virtual ~HWNDMessageHandlerDelegate() {} 243 }; 244 245 } // namespace views 246 247 #endif // UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_DELEGATE_H_ 248