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 changed. |visible| holds the new state. 157 virtual void HandleVisibilityChanged(bool visible) = 0; 158 159 // Called when the window's client size changed. |new_size| holds the new 160 // size. 161 virtual void HandleClientSizeChanged(const gfx::Size& new_size) = 0; 162 163 // Called when the window's frame has changed. 164 virtual void HandleFrameChanged() = 0; 165 166 // Called when focus shifted to this HWND from |last_focused_window|. 167 virtual void HandleNativeFocus(HWND last_focused_window) = 0; 168 169 // Called when focus shifted from the HWND to a different window. 170 virtual void HandleNativeBlur(HWND focused_window) = 0; 171 172 // Called when a mouse event is received. Returns true if the event was 173 // handled by the delegate. 174 virtual bool HandleMouseEvent(const ui::MouseEvent& event) = 0; 175 176 // Called when a translated key event is received (i.e. post IME translation.) 177 // Returns true if the event was handled by the delegate. 178 virtual bool HandleKeyEvent(const ui::KeyEvent& event) = 0; 179 180 // Called when an untranslated key event is received (i.e. pre-IME 181 // translation). Returns true if the event was sent to the input method. 182 virtual bool HandleUntranslatedKeyEvent(const ui::KeyEvent& event) = 0; 183 184 // Called when a touch event is received. Returns true if the event was 185 // handled by the delegate. 186 virtual bool HandleTouchEvent(const ui::TouchEvent& event) = 0; 187 188 // Called when an IME message needs to be processed by the delegate. Returns 189 // true if the event was handled and no default processing should be 190 // performed. 191 virtual bool HandleIMEMessage(UINT message, 192 WPARAM w_param, 193 LPARAM l_param, 194 LRESULT* result) = 0; 195 196 // Called when the system input language changes. 197 virtual void HandleInputLanguageChange(DWORD character_set, 198 HKL input_language_id) = 0; 199 200 // Called to compel the delegate to paint |invalid_rect| accelerated. Returns 201 // true if accelerated painting was performed. 202 virtual bool HandlePaintAccelerated(const gfx::Rect& invalid_rect) = 0; 203 204 // Called to compel the delegate to paint using the software path. 205 virtual void HandlePaint(gfx::Canvas* canvas) = 0; 206 207 // Called to forward a WM_NOTIFY message to the tooltip manager. 208 virtual bool HandleTooltipNotify(int w_param, 209 NMHDR* l_param, 210 LRESULT* l_result) = 0; 211 212 // Called to forward mouse events to the tooltip manager. 213 virtual void HandleTooltipMouseMove(UINT message, 214 WPARAM w_param, 215 LPARAM l_param) = 0; 216 217 // Catch-all message handling and filtering. Called before 218 // HWNDMessageHandler's built-in handling, which may pre-empt some 219 // expectations in Views/Aura if messages are consumed. Returns true if the 220 // message was consumed by the delegate and should not be processed further 221 // by the HWNDMessageHandler. In this case, |result| is returned. |result| is 222 // not modified otherwise. 223 virtual bool PreHandleMSG(UINT message, 224 WPARAM w_param, 225 LPARAM l_param, 226 LRESULT* result) = 0; 227 228 // Like PreHandleMSG, but called after HWNDMessageHandler's built-in handling 229 // has run and after DefWindowProc. 230 virtual void PostHandleMSG(UINT message, 231 WPARAM w_param, 232 LPARAM l_param) = 0; 233 234 protected: 235 virtual ~HWNDMessageHandlerDelegate() {} 236 }; 237 238 } // namespace views 239 240 #endif // UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_DELEGATE_H_ 241