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_WINDOW_TREE_HOST_WIN_H_
      6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_WIN_H_
      7 
      8 #include "ui/aura/window_tree_host.h"
      9 #include "ui/views/views_export.h"
     10 #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h"
     11 #include "ui/views/win/hwnd_message_handler_delegate.h"
     12 #include "ui/wm/public/animation_host.h"
     13 
     14 namespace aura {
     15 namespace client {
     16 class DragDropClient;
     17 class FocusClient;
     18 class ScopedTooltipDisabler;
     19 }
     20 }
     21 
     22 namespace views {
     23 class DesktopCursorClient;
     24 class DesktopDragDropClientWin;
     25 class HWNDMessageHandler;
     26 
     27 namespace corewm {
     28 class TooltipWin;
     29 }
     30 
     31 class VIEWS_EXPORT DesktopWindowTreeHostWin
     32     : public DesktopWindowTreeHost,
     33       public aura::client::AnimationHost,
     34       public aura::WindowTreeHost,
     35       public ui::EventSource,
     36       public HWNDMessageHandlerDelegate {
     37  public:
     38   DesktopWindowTreeHostWin(
     39       internal::NativeWidgetDelegate* native_widget_delegate,
     40       DesktopNativeWidgetAura* desktop_native_widget_aura);
     41   virtual ~DesktopWindowTreeHostWin();
     42 
     43   // A way of converting an HWND into a content window.
     44   static aura::Window* GetContentWindowForHWND(HWND hwnd);
     45 
     46  protected:
     47   // Overridden from DesktopWindowTreeHost:
     48   virtual void Init(aura::Window* content_window,
     49                     const Widget::InitParams& params) OVERRIDE;
     50   virtual void OnNativeWidgetCreated(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::WindowTreeHost* AsWindowTreeHost() 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 void SetVisibleOnAllWorkspaces(bool always_visible) OVERRIDE;
     84   virtual bool SetWindowTitle(const base::string16& title) OVERRIDE;
     85   virtual void ClearNativeFocus() OVERRIDE;
     86   virtual Widget::MoveLoopResult RunMoveLoop(
     87       const gfx::Vector2d& drag_offset,
     88       Widget::MoveLoopSource source,
     89       Widget::MoveLoopEscapeBehavior escape_behavior) OVERRIDE;
     90   virtual void EndMoveLoop() OVERRIDE;
     91   virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE;
     92   virtual bool ShouldUseNativeFrame() const OVERRIDE;
     93   virtual bool ShouldWindowContentsBeTransparent() const OVERRIDE;
     94   virtual void FrameTypeChanged() OVERRIDE;
     95   virtual void SetFullscreen(bool fullscreen) OVERRIDE;
     96   virtual bool IsFullscreen() const OVERRIDE;
     97   virtual void SetOpacity(unsigned char opacity) OVERRIDE;
     98   virtual void SetWindowIcons(const gfx::ImageSkia& window_icon,
     99                               const gfx::ImageSkia& app_icon) OVERRIDE;
    100   virtual void InitModalType(ui::ModalType modal_type) OVERRIDE;
    101   virtual void FlashFrame(bool flash_frame) OVERRIDE;
    102   virtual void OnRootViewLayout() const OVERRIDE;
    103   virtual void OnNativeWidgetFocus() OVERRIDE;
    104   virtual void OnNativeWidgetBlur() OVERRIDE;
    105   virtual bool IsAnimatingClosed() const OVERRIDE;
    106   virtual bool IsTranslucentWindowOpacitySupported() const OVERRIDE;
    107 
    108   // Overridden from aura::WindowTreeHost:
    109   virtual ui::EventSource* GetEventSource() OVERRIDE;
    110   virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
    111   virtual void Show() OVERRIDE;
    112   virtual void Hide() OVERRIDE;
    113   virtual gfx::Rect GetBounds() const OVERRIDE;
    114   virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
    115   virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
    116   virtual void SetCapture() OVERRIDE;
    117   virtual void ReleaseCapture() OVERRIDE;
    118   virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE;
    119   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
    120   virtual void SetCursorNative(gfx::NativeCursor cursor) OVERRIDE;
    121   virtual void OnCursorVisibilityChangedNative(bool show) OVERRIDE;
    122   virtual void MoveCursorToNative(const gfx::Point& location) OVERRIDE;
    123 
    124   // Overridden frm ui::EventSource
    125   virtual ui::EventProcessor* GetEventProcessor() OVERRIDE;
    126 
    127   // Overridden from aura::client::AnimationHost
    128   virtual void SetHostTransitionOffsets(
    129       const gfx::Vector2d& top_left_delta,
    130       const gfx::Vector2d& bottom_right_delta) 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 IsModal() const OVERRIDE;
    144   virtual int GetInitialShowState() const OVERRIDE;
    145   virtual bool WillProcessWorkAreaChange() const OVERRIDE;
    146   virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
    147   virtual void GetWindowMask(const gfx::Size& size, gfx::Path* path) OVERRIDE;
    148   virtual bool GetClientAreaInsets(gfx::Insets* insets) const OVERRIDE;
    149   virtual void GetMinMaxSize(gfx::Size* min_size,
    150                              gfx::Size* max_size) const OVERRIDE;
    151   virtual gfx::Size GetRootViewSize() const OVERRIDE;
    152   virtual void ResetWindowControls() OVERRIDE;
    153   virtual void PaintLayeredWindow(gfx::Canvas* canvas) OVERRIDE;
    154   virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
    155   virtual bool ShouldHandleSystemCommands() const OVERRIDE;
    156   virtual InputMethod* GetInputMethod() OVERRIDE;
    157   virtual void HandleAppDeactivated() OVERRIDE;
    158   virtual void HandleActivationChanged(bool active) OVERRIDE;
    159   virtual bool HandleAppCommand(short command) OVERRIDE;
    160   virtual void HandleCancelMode() OVERRIDE;
    161   virtual void HandleCaptureLost() OVERRIDE;
    162   virtual void HandleClose() OVERRIDE;
    163   virtual bool HandleCommand(int command) OVERRIDE;
    164   virtual void HandleAccelerator(const ui::Accelerator& accelerator) OVERRIDE;
    165   virtual void HandleCreate() OVERRIDE;
    166   virtual void HandleDestroying() OVERRIDE;
    167   virtual void HandleDestroyed() OVERRIDE;
    168   virtual bool HandleInitialFocus(ui::WindowShowState show_state) OVERRIDE;
    169   virtual void HandleDisplayChange() OVERRIDE;
    170   virtual void HandleBeginWMSizeMove() OVERRIDE;
    171   virtual void HandleEndWMSizeMove() OVERRIDE;
    172   virtual void HandleMove() OVERRIDE;
    173   virtual void HandleWorkAreaChanged() OVERRIDE;
    174   virtual void HandleVisibilityChanging(bool visible) OVERRIDE;
    175   virtual void HandleVisibilityChanged(bool visible) OVERRIDE;
    176   virtual void HandleClientSizeChanged(const gfx::Size& new_size) OVERRIDE;
    177   virtual void HandleFrameChanged() OVERRIDE;
    178   virtual void HandleNativeFocus(HWND last_focused_window) OVERRIDE;
    179   virtual void HandleNativeBlur(HWND focused_window) OVERRIDE;
    180   virtual bool HandleMouseEvent(const ui::MouseEvent& event) OVERRIDE;
    181   virtual bool HandleKeyEvent(const ui::KeyEvent& event) OVERRIDE;
    182   virtual bool HandleUntranslatedKeyEvent(const ui::KeyEvent& event) OVERRIDE;
    183   virtual void HandleTouchEvent(const ui::TouchEvent& event) OVERRIDE;
    184   virtual bool HandleIMEMessage(UINT message,
    185                                 WPARAM w_param,
    186                                 LPARAM l_param,
    187                                 LRESULT* result) OVERRIDE;
    188   virtual void HandleInputLanguageChange(DWORD character_set,
    189                                          HKL input_language_id) OVERRIDE;
    190   virtual bool HandlePaintAccelerated(const gfx::Rect& invalid_rect) OVERRIDE;
    191   virtual void HandlePaint(gfx::Canvas* canvas) OVERRIDE;
    192   virtual bool HandleTooltipNotify(int w_param,
    193                                    NMHDR* l_param,
    194                                    LRESULT* l_result) OVERRIDE;
    195   virtual void HandleTooltipMouseMove(UINT message,
    196                                       WPARAM w_param,
    197                                       LPARAM l_param) OVERRIDE;
    198   virtual void HandleMenuLoop(bool in_menu_loop) OVERRIDE;
    199   virtual bool PreHandleMSG(UINT message,
    200                             WPARAM w_param,
    201                             LPARAM l_param,
    202                             LRESULT* result) OVERRIDE;
    203   virtual void PostHandleMSG(UINT message,
    204                              WPARAM w_param,
    205                              LPARAM l_param) OVERRIDE;
    206   virtual bool HandleScrollEvent(const ui::ScrollEvent& event) OVERRIDE;
    207   virtual void HandleWindowSizeChanging() OVERRIDE;
    208 
    209   Widget* GetWidget();
    210   const Widget* GetWidget() const;
    211   HWND GetHWND() const;
    212 
    213  private:
    214   void SetWindowTransparency();
    215 
    216   // Returns true if a modal window is active in the current root window chain.
    217   bool IsModalWindowActive() const;
    218 
    219   scoped_ptr<HWNDMessageHandler> message_handler_;
    220   scoped_ptr<aura::client::FocusClient> focus_client_;
    221 
    222   // TODO(beng): Consider providing an interface to DesktopNativeWidgetAura
    223   //             instead of providing this route back to Widget.
    224   internal::NativeWidgetDelegate* native_widget_delegate_;
    225 
    226   DesktopNativeWidgetAura* desktop_native_widget_aura_;
    227 
    228   aura::Window* content_window_;
    229 
    230   // Owned by DesktopNativeWidgetAura.
    231   DesktopDragDropClientWin* drag_drop_client_;
    232 
    233   // When certain windows are being shown, we augment the window size
    234   // temporarily for animation. The following two members contain the top left
    235   // and bottom right offsets which are used to enlarge the window.
    236   gfx::Vector2d window_expansion_top_left_delta_;
    237   gfx::Vector2d window_expansion_bottom_right_delta_;
    238 
    239   // Windows are enlarged to be at least 64x64 pixels, so keep track of the
    240   // extra added here.
    241   gfx::Vector2d window_enlargement_;
    242 
    243   // Whether the window close should be converted to a hide, and then actually
    244   // closed on the completion of the hide animation. This is cached because
    245   // the property is set on the contained window which has a shorter lifetime.
    246   bool should_animate_window_close_;
    247 
    248   // When Close()d and animations are being applied to this window, the close
    249   // of the window needs to be deferred to when the close animation is
    250   // completed. This variable indicates that a Close was converted to a Hide,
    251   // so that when the Hide is completed the host window should be closed.
    252   bool pending_close_;
    253 
    254   // True if the widget is going to have a non_client_view. We cache this value
    255   // rather than asking the Widget for the non_client_view so that we know at
    256   // Init time, before the Widget has created the NonClientView.
    257   bool has_non_client_view_;
    258 
    259   // Owned by TooltipController, but we need to forward events to it so we keep
    260   // a reference.
    261   corewm::TooltipWin* tooltip_;
    262 
    263   // Visibility of the cursor. On Windows we can have multiple root windows and
    264   // the implementation of ::ShowCursor() is based on a counter, so making this
    265   // member static ensures that ::ShowCursor() is always called exactly once
    266   // whenever the cursor visibility state changes.
    267   static bool is_cursor_visible_;
    268 
    269   scoped_ptr<aura::client::ScopedTooltipDisabler> tooltip_disabler_;
    270 
    271   DISALLOW_COPY_AND_ASSIGN(DesktopWindowTreeHostWin);
    272 };
    273 
    274 }  // namespace views
    275 
    276 #endif  // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_WIN_H_
    277