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