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