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/window_tree_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 DragDropClient;
     17 class FocusClient;
     18 }
     19 }
     20 
     21 namespace views {
     22 class DesktopCursorClient;
     23 class DesktopDragDropClientWin;
     24 class HWNDMessageHandler;
     25 
     26 namespace corewm {
     27 class TooltipWin;
     28 }
     29 
     30 class VIEWS_EXPORT DesktopRootWindowHostWin
     31     : public DesktopRootWindowHost,
     32       public aura::client::AnimationHost,
     33       public aura::RootWindowHost,
     34       public HWNDMessageHandlerDelegate {
     35  public:
     36   DesktopRootWindowHostWin(
     37       internal::NativeWidgetDelegate* native_widget_delegate,
     38       DesktopNativeWidgetAura* desktop_native_widget_aura);
     39   virtual ~DesktopRootWindowHostWin();
     40 
     41   // A way of converting an HWND into a content window.
     42   static aura::Window* GetContentWindowForHWND(HWND hwnd);
     43 
     44  protected:
     45   // Overridden from DesktopRootWindowHost:
     46   virtual void Init(aura::Window* content_window,
     47                     const Widget::InitParams& params,
     48                     aura::RootWindow::CreateParams* rw_create_params) OVERRIDE;
     49   virtual void OnRootWindowCreated(aura::RootWindow* root,
     50                                    const Widget::InitParams& params) OVERRIDE;
     51   virtual scoped_ptr<corewm::Tooltip> CreateTooltip() OVERRIDE;
     52   virtual scoped_ptr<aura::client::DragDropClient>
     53       CreateDragDropClient(DesktopNativeCursorManager* cursor_manager) OVERRIDE;
     54   virtual void Close() OVERRIDE;
     55   virtual void CloseNow() OVERRIDE;
     56   virtual aura::RootWindowHost* AsRootWindowHost() OVERRIDE;
     57   virtual void ShowWindowWithState(ui::WindowShowState show_state) OVERRIDE;
     58   virtual void ShowMaximizedWithBounds(
     59       const gfx::Rect& restored_bounds) OVERRIDE;
     60   virtual bool IsVisible() const OVERRIDE;
     61   virtual void SetSize(const gfx::Size& size) OVERRIDE;
     62   virtual void StackAtTop() OVERRIDE;
     63   virtual void CenterWindow(const gfx::Size& size) OVERRIDE;
     64   virtual void GetWindowPlacement(
     65       gfx::Rect* bounds,
     66       ui::WindowShowState* show_state) const OVERRIDE;
     67   virtual gfx::Rect GetWindowBoundsInScreen() const OVERRIDE;
     68   virtual gfx::Rect GetClientAreaBoundsInScreen() const OVERRIDE;
     69   virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
     70   virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
     71   virtual void SetShape(gfx::NativeRegion native_region) OVERRIDE;
     72   virtual void Activate() OVERRIDE;
     73   virtual void Deactivate() OVERRIDE;
     74   virtual bool IsActive() const OVERRIDE;
     75   virtual void Maximize() OVERRIDE;
     76   virtual void Minimize() OVERRIDE;
     77   virtual void Restore() OVERRIDE;
     78   virtual bool IsMaximized() const OVERRIDE;
     79   virtual bool IsMinimized() const OVERRIDE;
     80   virtual bool HasCapture() const OVERRIDE;
     81   virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
     82   virtual bool IsAlwaysOnTop() const OVERRIDE;
     83   virtual bool SetWindowTitle(const string16& title) OVERRIDE;
     84   virtual void ClearNativeFocus() OVERRIDE;
     85   virtual Widget::MoveLoopResult RunMoveLoop(
     86       const gfx::Vector2d& drag_offset,
     87       Widget::MoveLoopSource source,
     88       Widget::MoveLoopEscapeBehavior escape_behavior) OVERRIDE;
     89   virtual void EndMoveLoop() OVERRIDE;
     90   virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE;
     91   virtual bool ShouldUseNativeFrame() OVERRIDE;
     92   virtual void FrameTypeChanged() OVERRIDE;
     93   virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
     94   virtual void SetFullscreen(bool fullscreen) OVERRIDE;
     95   virtual bool IsFullscreen() const OVERRIDE;
     96   virtual void SetOpacity(unsigned char opacity) OVERRIDE;
     97   virtual void SetWindowIcons(const gfx::ImageSkia& window_icon,
     98                               const gfx::ImageSkia& app_icon) OVERRIDE;
     99   virtual void InitModalType(ui::ModalType modal_type) OVERRIDE;
    100   virtual void FlashFrame(bool flash_frame) OVERRIDE;
    101   virtual void OnRootViewLayout() const OVERRIDE;
    102   virtual void OnNativeWidgetFocus() OVERRIDE;
    103   virtual void OnNativeWidgetBlur() OVERRIDE;
    104   virtual bool IsAnimatingClosed() const OVERRIDE;
    105 
    106   // Overridden from aura::RootWindowHost:
    107   virtual aura::RootWindow* GetRootWindow() OVERRIDE;
    108   virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
    109   virtual void Show() OVERRIDE;
    110   virtual void Hide() OVERRIDE;
    111   virtual void ToggleFullScreen() OVERRIDE;
    112   virtual gfx::Rect GetBounds() const OVERRIDE;
    113   virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
    114   virtual gfx::Insets GetInsets() const OVERRIDE;
    115   virtual void SetInsets(const gfx::Insets& insets) OVERRIDE;
    116   virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
    117   virtual void SetCapture() OVERRIDE;
    118   virtual void ReleaseCapture() OVERRIDE;
    119   virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
    120   virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
    121   virtual bool ConfineCursorToRootWindow() OVERRIDE;
    122   virtual void UnConfineCursor() OVERRIDE;
    123   virtual void OnCursorVisibilityChanged(bool show) OVERRIDE;
    124   virtual void MoveCursorTo(const gfx::Point& location) 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 SetHostTransitionOffsets(
    131       const gfx::Vector2d& top_left_delta,
    132       const gfx::Vector2d& bottom_right_delta) OVERRIDE;
    133   virtual void OnWindowHidingAnimationCompleted() OVERRIDE;
    134 
    135   // Overridden from HWNDMessageHandlerDelegate:
    136   virtual bool IsWidgetWindow() const OVERRIDE;
    137   virtual bool IsUsingCustomFrame() const OVERRIDE;
    138   virtual void SchedulePaint() OVERRIDE;
    139   virtual void EnableInactiveRendering() OVERRIDE;
    140   virtual bool IsInactiveRenderingDisabled() OVERRIDE;
    141   virtual bool CanResize() const OVERRIDE;
    142   virtual bool CanMaximize() const OVERRIDE;
    143   virtual bool CanActivate() const OVERRIDE;
    144   virtual bool WidgetSizeIsClientSize() const OVERRIDE;
    145   virtual bool CanSaveFocus() const OVERRIDE;
    146   virtual void SaveFocusOnDeactivate() OVERRIDE;
    147   virtual void RestoreFocusOnActivate() OVERRIDE;
    148   virtual void RestoreFocusOnEnable() OVERRIDE;
    149   virtual bool IsModal() const OVERRIDE;
    150   virtual int GetInitialShowState() const OVERRIDE;
    151   virtual bool WillProcessWorkAreaChange() const OVERRIDE;
    152   virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
    153   virtual void GetWindowMask(const gfx::Size& size, gfx::Path* path) OVERRIDE;
    154   virtual bool GetClientAreaInsets(gfx::Insets* insets) const OVERRIDE;
    155   virtual void GetMinMaxSize(gfx::Size* min_size,
    156                              gfx::Size* max_size) const OVERRIDE;
    157   virtual gfx::Size GetRootViewSize() const OVERRIDE;
    158   virtual void ResetWindowControls() OVERRIDE;
    159   virtual void PaintLayeredWindow(gfx::Canvas* canvas) OVERRIDE;
    160   virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
    161   virtual bool ShouldHandleSystemCommands() const OVERRIDE;
    162   virtual InputMethod* GetInputMethod() OVERRIDE;
    163   virtual void HandleAppDeactivated() OVERRIDE;
    164   virtual void HandleActivationChanged(bool active) OVERRIDE;
    165   virtual bool HandleAppCommand(short command) OVERRIDE;
    166   virtual void HandleCancelMode() OVERRIDE;
    167   virtual void HandleCaptureLost() OVERRIDE;
    168   virtual void HandleClose() OVERRIDE;
    169   virtual bool HandleCommand(int command) OVERRIDE;
    170   virtual void HandleAccelerator(const ui::Accelerator& accelerator) OVERRIDE;
    171   virtual void HandleCreate() OVERRIDE;
    172   virtual void HandleDestroying() OVERRIDE;
    173   virtual void HandleDestroyed() OVERRIDE;
    174   virtual bool HandleInitialFocus() OVERRIDE;
    175   virtual void HandleDisplayChange() OVERRIDE;
    176   virtual void HandleBeginWMSizeMove() OVERRIDE;
    177   virtual void HandleEndWMSizeMove() OVERRIDE;
    178   virtual void HandleMove() OVERRIDE;
    179   virtual void HandleWorkAreaChanged() OVERRIDE;
    180   virtual void HandleVisibilityChanging(bool visible) OVERRIDE;
    181   virtual void HandleVisibilityChanged(bool visible) OVERRIDE;
    182   virtual void HandleClientSizeChanged(const gfx::Size& new_size) OVERRIDE;
    183   virtual void HandleFrameChanged() OVERRIDE;
    184   virtual void HandleNativeFocus(HWND last_focused_window) OVERRIDE;
    185   virtual void HandleNativeBlur(HWND focused_window) OVERRIDE;
    186   virtual bool HandleMouseEvent(const ui::MouseEvent& event) OVERRIDE;
    187   virtual bool HandleKeyEvent(const ui::KeyEvent& event) OVERRIDE;
    188   virtual bool HandleUntranslatedKeyEvent(const ui::KeyEvent& event) OVERRIDE;
    189   virtual void HandleTouchEvent(const ui::TouchEvent& event) OVERRIDE;
    190   virtual bool HandleIMEMessage(UINT message,
    191                                 WPARAM w_param,
    192                                 LPARAM l_param,
    193                                 LRESULT* result) OVERRIDE;
    194   virtual void HandleInputLanguageChange(DWORD character_set,
    195                                          HKL input_language_id) OVERRIDE;
    196   virtual bool HandlePaintAccelerated(const gfx::Rect& invalid_rect) OVERRIDE;
    197   virtual void HandlePaint(gfx::Canvas* canvas) OVERRIDE;
    198   virtual bool HandleTooltipNotify(int w_param,
    199                                    NMHDR* l_param,
    200                                    LRESULT* l_result) OVERRIDE;
    201   virtual void HandleTooltipMouseMove(UINT message,
    202                                       WPARAM w_param,
    203                                       LPARAM l_param) OVERRIDE;
    204   virtual bool PreHandleMSG(UINT message,
    205                             WPARAM w_param,
    206                             LPARAM l_param,
    207                             LRESULT* result) OVERRIDE;
    208   virtual void PostHandleMSG(UINT message,
    209                              WPARAM w_param,
    210                              LPARAM l_param) OVERRIDE;
    211   virtual bool HandleScrollEvent(const ui::ScrollEvent& event) OVERRIDE;
    212 
    213   Widget* GetWidget();
    214   const Widget* GetWidget() const;
    215   HWND GetHWND() const;
    216 
    217  private:
    218   void SetWindowTransparency();
    219 
    220   // Returns true if a modal window is active in the current root window chain.
    221   bool IsModalWindowActive() const;
    222 
    223   // We are owned by the RootWindow, but we have to have a back pointer to it.
    224   aura::RootWindow* root_window_;
    225 
    226   scoped_ptr<HWNDMessageHandler> message_handler_;
    227   scoped_ptr<aura::client::FocusClient> focus_client_;
    228 
    229   // TODO(beng): Consider providing an interface to DesktopNativeWidgetAura
    230   //             instead of providing this route back to Widget.
    231   internal::NativeWidgetDelegate* native_widget_delegate_;
    232 
    233   DesktopNativeWidgetAura* desktop_native_widget_aura_;
    234 
    235   aura::Window* content_window_;
    236 
    237   // Owned by DesktopNativeWidgetAura.
    238   DesktopDragDropClientWin* drag_drop_client_;
    239 
    240   // When certain windows are being shown, we augment the window size
    241   // temporarily for animation. The following two members contain the top left
    242   // and bottom right offsets which are used to enlarge the window.
    243   gfx::Vector2d window_expansion_top_left_delta_;
    244   gfx::Vector2d window_expansion_bottom_right_delta_;
    245 
    246   // Windows are enlarged to be at least 64x64 pixels, so keep track of the
    247   // extra added here.
    248   gfx::Vector2d window_enlargement_;
    249 
    250   // Whether the window close should be converted to a hide, and then actually
    251   // closed on the completion of the hide animation. This is cached because
    252   // the property is set on the contained window which has a shorter lifetime.
    253   bool should_animate_window_close_;
    254 
    255   // When Close()d and animations are being applied to this window, the close
    256   // of the window needs to be deferred to when the close animation is
    257   // completed. This variable indicates that a Close was converted to a Hide,
    258   // so that when the Hide is completed the host window should be closed.
    259   bool pending_close_;
    260 
    261   // True if the widget is going to have a non_client_view. We cache this value
    262   // rather than asking the Widget for the non_client_view so that we know at
    263   // Init time, before the Widget has created the NonClientView.
    264   bool has_non_client_view_;
    265 
    266   // Owned by TooltipController, but we need to forward events to it so we keep
    267   // a reference.
    268   corewm::TooltipWin* tooltip_;
    269 
    270   // State of the cursor.
    271   bool is_cursor_visible_;
    272 
    273   DISALLOW_COPY_AND_ASSIGN(DesktopRootWindowHostWin);
    274 };
    275 
    276 }  // namespace views
    277 
    278 #endif  // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_ROOT_WINDOW_HOST_WIN_H_
    279