Home | History | Annotate | Download | only in desktop_aura
      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_WIDGET_DESKTOP_AURA_DESKTOP_ROOT_WINDOW_HOST_WIN_H_
      6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_ROOT_WINDOW_HOST_WIN_H_
      7 
      8 #include "ui/aura/client/animation_host.h"
      9 #include "ui/aura/root_window_host.h"
     10 #include "ui/views/views_export.h"
     11 #include "ui/views/widget/desktop_aura/desktop_root_window_host.h"
     12 #include "ui/views/win/hwnd_message_handler_delegate.h"
     13 
     14 namespace aura {
     15 namespace client {
     16 class FocusClient;
     17 class ScreenPositionClient;
     18 }
     19 }
     20 
     21 namespace views {
     22 class DesktopActivationClient;
     23 class DesktopCaptureClient;
     24 class DesktopCursorClient;
     25 class DesktopDispatcherClient;
     26 class DesktopDragDropClientWin;
     27 class HWNDMessageHandler;
     28 
     29 namespace corewm {
     30 class CursorManager;
     31 }
     32 
     33 class VIEWS_EXPORT DesktopRootWindowHostWin
     34     : public DesktopRootWindowHost,
     35       public aura::client::AnimationHost,
     36       public aura::RootWindowHost,
     37       public HWNDMessageHandlerDelegate {
     38  public:
     39   DesktopRootWindowHostWin(
     40       internal::NativeWidgetDelegate* native_widget_delegate,
     41       DesktopNativeWidgetAura* desktop_native_widget_aura,
     42       const gfx::Rect& initial_bounds);
     43   virtual ~DesktopRootWindowHostWin();
     44 
     45   // A way of converting an HWND into a content window.
     46   static aura::Window* GetContentWindowForHWND(HWND hwnd);
     47 
     48  protected:
     49   // Overridden from DesktopRootWindowHost:
     50   virtual aura::RootWindow* Init(aura::Window* content_window,
     51                                  const Widget::InitParams& params) OVERRIDE;
     52   virtual void InitFocus(aura::Window* window) OVERRIDE;
     53   virtual void Close() OVERRIDE;
     54   virtual void CloseNow() OVERRIDE;
     55   virtual aura::RootWindowHost* AsRootWindowHost() OVERRIDE;
     56   virtual void ShowWindowWithState(ui::WindowShowState show_state) OVERRIDE;
     57   virtual void ShowMaximizedWithBounds(
     58       const gfx::Rect& restored_bounds) OVERRIDE;
     59   virtual bool IsVisible() const OVERRIDE;
     60   virtual void SetSize(const gfx::Size& size) OVERRIDE;
     61   virtual void CenterWindow(const gfx::Size& size) OVERRIDE;
     62   virtual void GetWindowPlacement(
     63       gfx::Rect* bounds,
     64       ui::WindowShowState* show_state) const OVERRIDE;
     65   virtual gfx::Rect GetWindowBoundsInScreen() const OVERRIDE;
     66   virtual gfx::Rect GetClientAreaBoundsInScreen() const OVERRIDE;
     67   virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
     68   virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
     69   virtual void SetShape(gfx::NativeRegion native_region) OVERRIDE;
     70   virtual void Activate() OVERRIDE;
     71   virtual void Deactivate() OVERRIDE;
     72   virtual bool IsActive() const OVERRIDE;
     73   virtual void Maximize() OVERRIDE;
     74   virtual void Minimize() OVERRIDE;
     75   virtual void Restore() OVERRIDE;
     76   virtual bool IsMaximized() const OVERRIDE;
     77   virtual bool IsMinimized() const OVERRIDE;
     78   virtual bool HasCapture() const OVERRIDE;
     79   virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
     80   virtual void SetWindowTitle(const string16& title) OVERRIDE;
     81   virtual void ClearNativeFocus() OVERRIDE;
     82   virtual Widget::MoveLoopResult RunMoveLoop(
     83       const gfx::Vector2d& drag_offset,
     84       Widget::MoveLoopSource source) OVERRIDE;
     85   virtual void EndMoveLoop() OVERRIDE;
     86   virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE;
     87   virtual bool ShouldUseNativeFrame() OVERRIDE;
     88   virtual void FrameTypeChanged() OVERRIDE;
     89   virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
     90   virtual void SetFullscreen(bool fullscreen) OVERRIDE;
     91   virtual bool IsFullscreen() const OVERRIDE;
     92   virtual void SetOpacity(unsigned char opacity) OVERRIDE;
     93   virtual void SetWindowIcons(const gfx::ImageSkia& window_icon,
     94                               const gfx::ImageSkia& app_icon) OVERRIDE;
     95   virtual void InitModalType(ui::ModalType modal_type) OVERRIDE;
     96   virtual void FlashFrame(bool flash_frame) OVERRIDE;
     97   virtual void OnNativeWidgetFocus() OVERRIDE;
     98   virtual void OnNativeWidgetBlur() OVERRIDE;
     99   virtual void SetInactiveRenderingDisabled(bool disable_inactive) OVERRIDE;
    100 
    101   // Overridden from aura::RootWindowHost:
    102   virtual void SetDelegate(aura::RootWindowHostDelegate* delegate) OVERRIDE;
    103   virtual aura::RootWindow* GetRootWindow() OVERRIDE;
    104   virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
    105   virtual void Show() OVERRIDE;
    106   virtual void Hide() OVERRIDE;
    107   virtual void ToggleFullScreen() OVERRIDE;
    108   virtual gfx::Rect GetBounds() const OVERRIDE;
    109   virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
    110   virtual gfx::Insets GetInsets() const OVERRIDE;
    111   virtual void SetInsets(const gfx::Insets& insets) OVERRIDE;
    112   virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
    113   virtual void SetCapture() OVERRIDE;
    114   virtual void ReleaseCapture() OVERRIDE;
    115   virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
    116   virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
    117   virtual bool ConfineCursorToRootWindow() OVERRIDE;
    118   virtual void UnConfineCursor() OVERRIDE;
    119   virtual void OnCursorVisibilityChanged(bool show) OVERRIDE;
    120   virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE;
    121   virtual void SetFocusWhenShown(bool focus_when_shown) OVERRIDE;
    122   virtual bool CopyAreaToSkCanvas(const gfx::Rect& source_bounds,
    123                                   const gfx::Point& dest_offset,
    124                                   SkCanvas* canvas) OVERRIDE;
    125   virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE;
    126   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
    127   virtual void PrepareForShutdown() OVERRIDE;
    128 
    129   // Overridden from aura::client::AnimationHost
    130   virtual void SetHostTransitionBounds(const gfx::Rect& bounds) OVERRIDE;
    131   virtual void OnWindowHidingAnimationCompleted() OVERRIDE;
    132 
    133   // Overridden from HWNDMessageHandlerDelegate:
    134   virtual bool IsWidgetWindow() const OVERRIDE;
    135   virtual bool IsUsingCustomFrame() const OVERRIDE;
    136   virtual void SchedulePaint() OVERRIDE;
    137   virtual void EnableInactiveRendering() OVERRIDE;
    138   virtual bool IsInactiveRenderingDisabled() OVERRIDE;
    139   virtual bool CanResize() const OVERRIDE;
    140   virtual bool CanMaximize() const OVERRIDE;
    141   virtual bool CanActivate() const OVERRIDE;
    142   virtual bool WidgetSizeIsClientSize() const OVERRIDE;
    143   virtual bool CanSaveFocus() const OVERRIDE;
    144   virtual void SaveFocusOnDeactivate() OVERRIDE;
    145   virtual void RestoreFocusOnActivate() OVERRIDE;
    146   virtual void RestoreFocusOnEnable() OVERRIDE;
    147   virtual bool IsModal() const OVERRIDE;
    148   virtual int GetInitialShowState() const OVERRIDE;
    149   virtual bool WillProcessWorkAreaChange() const OVERRIDE;
    150   virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
    151   virtual void GetWindowMask(const gfx::Size& size, gfx::Path* path) OVERRIDE;
    152   virtual bool GetClientAreaInsets(gfx::Insets* insets) const OVERRIDE;
    153   virtual void GetMinMaxSize(gfx::Size* min_size,
    154                              gfx::Size* max_size) const OVERRIDE;
    155   virtual gfx::Size GetRootViewSize() const OVERRIDE;
    156   virtual void ResetWindowControls() OVERRIDE;
    157   virtual void PaintLayeredWindow(gfx::Canvas* canvas) OVERRIDE;
    158   virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
    159   virtual bool ShouldHandleSystemCommands() const OVERRIDE;
    160   virtual InputMethod* GetInputMethod() OVERRIDE;
    161   virtual void HandleAppDeactivated() OVERRIDE;
    162   virtual void HandleActivationChanged(bool active) OVERRIDE;
    163   virtual bool HandleAppCommand(short command) OVERRIDE;
    164   virtual void HandleCancelMode() OVERRIDE;
    165   virtual void HandleCaptureLost() OVERRIDE;
    166   virtual void HandleClose() OVERRIDE;
    167   virtual bool HandleCommand(int command) OVERRIDE;
    168   virtual void HandleAccelerator(const ui::Accelerator& accelerator) OVERRIDE;
    169   virtual void HandleCreate() OVERRIDE;
    170   virtual void HandleDestroying() OVERRIDE;
    171   virtual void HandleDestroyed() OVERRIDE;
    172   virtual bool HandleInitialFocus() OVERRIDE;
    173   virtual void HandleDisplayChange() OVERRIDE;
    174   virtual void HandleBeginWMSizeMove() OVERRIDE;
    175   virtual void HandleEndWMSizeMove() OVERRIDE;
    176   virtual void HandleMove() OVERRIDE;
    177   virtual void HandleWorkAreaChanged() OVERRIDE;
    178   virtual void HandleVisibilityChanged(bool visible) OVERRIDE;
    179   virtual void HandleClientSizeChanged(const gfx::Size& new_size) OVERRIDE;
    180   virtual void HandleFrameChanged() OVERRIDE;
    181   virtual void HandleNativeFocus(HWND last_focused_window) OVERRIDE;
    182   virtual void HandleNativeBlur(HWND focused_window) OVERRIDE;
    183   virtual bool HandleMouseEvent(const ui::MouseEvent& event) OVERRIDE;
    184   virtual bool HandleKeyEvent(const ui::KeyEvent& event) OVERRIDE;
    185   virtual bool HandleUntranslatedKeyEvent(const ui::KeyEvent& event) OVERRIDE;
    186   virtual bool HandleTouchEvent(const ui::TouchEvent& event) OVERRIDE;
    187   virtual bool HandleIMEMessage(UINT message,
    188                                 WPARAM w_param,
    189                                 LPARAM l_param,
    190                                 LRESULT* result) OVERRIDE;
    191   virtual void HandleInputLanguageChange(DWORD character_set,
    192                                          HKL input_language_id) OVERRIDE;
    193   virtual bool HandlePaintAccelerated(const gfx::Rect& invalid_rect) OVERRIDE;
    194   virtual void HandlePaint(gfx::Canvas* canvas) OVERRIDE;
    195   virtual bool HandleTooltipNotify(int w_param,
    196                                    NMHDR* l_param,
    197                                    LRESULT* l_result) OVERRIDE;
    198   virtual void HandleTooltipMouseMove(UINT message,
    199                                       WPARAM w_param,
    200                                       LPARAM l_param) OVERRIDE;
    201   virtual bool PreHandleMSG(UINT message,
    202                             WPARAM w_param,
    203                             LPARAM l_param,
    204                             LRESULT* result) OVERRIDE;
    205   virtual void PostHandleMSG(UINT message,
    206                              WPARAM w_param,
    207                              LPARAM l_param) OVERRIDE;
    208 
    209   Widget* GetWidget();
    210   const Widget* GetWidget() const;
    211   HWND GetHWND() const;
    212 
    213  private:
    214   // We are owned by the RootWindow, but we have to have a back pointer to it.
    215   aura::RootWindow* root_window_;
    216 
    217   scoped_ptr<HWNDMessageHandler> message_handler_;
    218   scoped_ptr<DesktopCaptureClient> capture_client_;
    219   scoped_ptr<DesktopDispatcherClient> dispatcher_client_;
    220   scoped_ptr<aura::client::FocusClient> focus_client_;
    221   // Depends on focus_manager_.
    222   scoped_ptr<DesktopActivationClient> activation_client_;
    223 
    224   // TODO(beng): Consider providing an interface to DesktopNativeWidgetAura
    225   //             instead of providing this route back to Widget.
    226   internal::NativeWidgetDelegate* native_widget_delegate_;
    227 
    228   DesktopNativeWidgetAura* desktop_native_widget_aura_;
    229 
    230   aura::RootWindowHostDelegate* root_window_host_delegate_;
    231   aura::Window* content_window_;
    232 
    233   // In some cases, we set a screen position client on |root_window_|. If we
    234   // do, we're responsible for the lifetime.
    235   scoped_ptr<aura::client::ScreenPositionClient> position_client_;
    236 
    237   // Controls visibility of the cursor.
    238   scoped_ptr<views::corewm::CursorManager> cursor_client_;
    239 
    240   scoped_ptr<DesktopDragDropClientWin> drag_drop_client_;
    241 
    242   // Extra size added to the host window. Typically, the window size matches
    243   // the contained content, however, when performing a translating or scaling
    244   // animation the window has to be enlarged so that the content is not
    245   // clipped.
    246   gfx::Rect window_expansion_;
    247 
    248   // Whether the window close should be converted to a hide, and then actually
    249   // closed on the completion of the hide animation. This is cached because
    250   // the property is set on the contained window which has a shorter lifetime.
    251   bool should_animate_window_close_;
    252 
    253   // When Close()d and animations are being applied to this window, the close
    254   // of the window needs to be deferred to when the close animation is
    255   // completed. This variable indicates that a Close was converted to a Hide,
    256   // so that when the Hide is completed the host window should be closed.
    257   bool pending_close_;
    258 
    259   // True if the widget is going to have a non_client_view. We cache this value
    260   // rather than asking the Widget for the non_client_view so that we know at
    261   // Init time, before the Widget has created the NonClientView.
    262   bool has_non_client_view_;
    263 
    264   DISALLOW_COPY_AND_ASSIGN(DesktopRootWindowHostWin);
    265 };
    266 
    267 }  // namespace views
    268 
    269 #endif  // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_ROOT_WINDOW_HOST_WIN_H_
    270