Home | History | Annotate | Download | only in widget
      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_NATIVE_WIDGET_AURA_H_
      6 #define UI_VIEWS_WIDGET_NATIVE_WIDGET_AURA_H_
      7 
      8 #include "base/memory/scoped_vector.h"
      9 #include "base/memory/weak_ptr.h"
     10 #include "ui/aura/client/activation_change_observer.h"
     11 #include "ui/aura/client/activation_delegate.h"
     12 #include "ui/aura/client/drag_drop_delegate.h"
     13 #include "ui/aura/client/focus_change_observer.h"
     14 #include "ui/aura/window_delegate.h"
     15 #include "ui/base/events/event_constants.h"
     16 #include "ui/views/ime/input_method_delegate.h"
     17 #include "ui/views/views_export.h"
     18 #include "ui/views/widget/native_widget_private.h"
     19 
     20 namespace aura {
     21 class Window;
     22 }
     23 namespace gfx {
     24 class Font;
     25 }
     26 
     27 namespace views {
     28 
     29 class DropHelper;
     30 class NativeWidgetAuraWindowObserver;
     31 class TooltipManagerAura;
     32 class WindowReorderer;
     33 
     34 class VIEWS_EXPORT NativeWidgetAura
     35     : public internal::NativeWidgetPrivate,
     36       public internal::InputMethodDelegate,
     37       public aura::WindowDelegate,
     38       public aura::client::ActivationDelegate,
     39       public aura::client::ActivationChangeObserver,
     40       public aura::client::FocusChangeObserver,
     41       public aura::client::DragDropDelegate {
     42  public:
     43   explicit NativeWidgetAura(internal::NativeWidgetDelegate* delegate);
     44 
     45   // TODO(beng): Find a better place for this, and the similar method on
     46   //             NativeWidgetWin.
     47   static gfx::Font GetWindowTitleFont();
     48 
     49   // Overridden from internal::NativeWidgetPrivate:
     50   virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
     51   virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
     52   virtual bool ShouldUseNativeFrame() const OVERRIDE;
     53   virtual void FrameTypeChanged() OVERRIDE;
     54   virtual Widget* GetWidget() OVERRIDE;
     55   virtual const Widget* GetWidget() const OVERRIDE;
     56   virtual gfx::NativeView GetNativeView() const OVERRIDE;
     57   virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE;
     58   virtual Widget* GetTopLevelWidget() OVERRIDE;
     59   virtual const ui::Compositor* GetCompositor() const OVERRIDE;
     60   virtual ui::Compositor* GetCompositor() OVERRIDE;
     61   virtual ui::Layer* GetLayer() OVERRIDE;
     62   virtual void ReorderNativeViews() OVERRIDE;
     63   virtual void ViewRemoved(View* view) OVERRIDE;
     64   virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE;
     65   virtual void* GetNativeWindowProperty(const char* name) const OVERRIDE;
     66   virtual TooltipManager* GetTooltipManager() const OVERRIDE;
     67   virtual void SetCapture() OVERRIDE;
     68   virtual void ReleaseCapture() OVERRIDE;
     69   virtual bool HasCapture() const OVERRIDE;
     70   virtual InputMethod* CreateInputMethod() OVERRIDE;
     71   virtual internal::InputMethodDelegate* GetInputMethodDelegate() OVERRIDE;
     72   virtual void CenterWindow(const gfx::Size& size) OVERRIDE;
     73   virtual void GetWindowPlacement(
     74       gfx::Rect* bounds,
     75       ui::WindowShowState* maximized) const OVERRIDE;
     76   virtual void SetWindowTitle(const string16& title) OVERRIDE;
     77   virtual void SetWindowIcons(const gfx::ImageSkia& window_icon,
     78                               const gfx::ImageSkia& app_icon) OVERRIDE;
     79   virtual void InitModalType(ui::ModalType modal_type) OVERRIDE;
     80   virtual gfx::Rect GetWindowBoundsInScreen() const OVERRIDE;
     81   virtual gfx::Rect GetClientAreaBoundsInScreen() const OVERRIDE;
     82   virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
     83   virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
     84   virtual void SetSize(const gfx::Size& size) OVERRIDE;
     85   virtual void StackAbove(gfx::NativeView native_view) OVERRIDE;
     86   virtual void StackAtTop() OVERRIDE;
     87   virtual void StackBelow(gfx::NativeView native_view) OVERRIDE;
     88   virtual void SetShape(gfx::NativeRegion shape) OVERRIDE;
     89   virtual void Close() OVERRIDE;
     90   virtual void CloseNow() OVERRIDE;
     91   virtual void Show() OVERRIDE;
     92   virtual void Hide() OVERRIDE;
     93   virtual void ShowMaximizedWithBounds(
     94       const gfx::Rect& restored_bounds) OVERRIDE;
     95   virtual void ShowWithWindowState(ui::WindowShowState state) OVERRIDE;
     96   virtual bool IsVisible() const OVERRIDE;
     97   virtual void Activate() OVERRIDE;
     98   virtual void Deactivate() OVERRIDE;
     99   virtual bool IsActive() const OVERRIDE;
    100   virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
    101   virtual void Maximize() OVERRIDE;
    102   virtual void Minimize() OVERRIDE;
    103   virtual bool IsMaximized() const OVERRIDE;
    104   virtual bool IsMinimized() const OVERRIDE;
    105   virtual void Restore() OVERRIDE;
    106   virtual void SetFullscreen(bool fullscreen) OVERRIDE;
    107   virtual bool IsFullscreen() const OVERRIDE;
    108   virtual void SetOpacity(unsigned char opacity) OVERRIDE;
    109   virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE;
    110   virtual void FlashFrame(bool flash_frame) OVERRIDE;
    111   virtual void RunShellDrag(View* view,
    112                             const ui::OSExchangeData& data,
    113                             const gfx::Point& location,
    114                             int operation,
    115                             ui::DragDropTypes::DragEventSource source) OVERRIDE;
    116   virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
    117   virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
    118   virtual bool IsMouseEventsEnabled() const OVERRIDE;
    119   virtual void ClearNativeFocus() OVERRIDE;
    120   virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
    121   virtual void SetInactiveRenderingDisabled(bool value) OVERRIDE;
    122   virtual Widget::MoveLoopResult RunMoveLoop(
    123       const gfx::Vector2d& drag_offset,
    124       Widget::MoveLoopSource source) OVERRIDE;
    125   virtual void EndMoveLoop() OVERRIDE;
    126   virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE;
    127   virtual ui::NativeTheme* GetNativeTheme() const OVERRIDE;
    128 
    129   // Overridden from views::InputMethodDelegate:
    130   virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE;
    131 
    132   // Overridden from aura::WindowDelegate:
    133   virtual gfx::Size GetMinimumSize() const OVERRIDE;
    134   virtual gfx::Size GetMaximumSize() const OVERRIDE;
    135   virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
    136                                const gfx::Rect& new_bounds) OVERRIDE;
    137   virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
    138   virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
    139   virtual bool ShouldDescendIntoChildForEventHandling(
    140       aura::Window* child,
    141       const gfx::Point& location) OVERRIDE;
    142   virtual bool CanFocus() OVERRIDE;
    143   virtual void OnCaptureLost() OVERRIDE;
    144   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
    145   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
    146   virtual void OnWindowDestroying() OVERRIDE;
    147   virtual void OnWindowDestroyed() OVERRIDE;
    148   virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE;
    149   virtual bool HasHitTestMask() const OVERRIDE;
    150   virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
    151   virtual scoped_refptr<ui::Texture> CopyTexture() OVERRIDE;
    152 
    153   // Overridden from ui::EventHandler:
    154   virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
    155   virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
    156   virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
    157   virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
    158   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
    159 
    160   // Overridden from aura::client::ActivationDelegate:
    161   virtual bool ShouldActivate() const OVERRIDE;
    162 
    163   // Overridden from aura::client::ActivationChangeObserver:
    164   virtual void OnWindowActivated(aura::Window* gained_active,
    165                                  aura::Window* lost_active) OVERRIDE;
    166 
    167   // Overridden from aura::client::FocusChangeObserver:
    168   virtual void OnWindowFocused(aura::Window* gained_focus,
    169                                aura::Window* lost_focus) OVERRIDE;
    170 
    171   // Overridden from aura::client::DragDropDelegate:
    172   virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE;
    173   virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
    174   virtual void OnDragExited() OVERRIDE;
    175   virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
    176 
    177   // Overridden from NativeWidget:
    178   virtual ui::EventHandler* GetEventHandler() OVERRIDE;
    179 
    180  protected:
    181   virtual ~NativeWidgetAura();
    182 
    183   internal::NativeWidgetDelegate* delegate() { return delegate_; }
    184 
    185  private:
    186   class ActiveWindowObserver;
    187 
    188   void SetInitialFocus();
    189 
    190   internal::NativeWidgetDelegate* delegate_;
    191 
    192   aura::Window* window_;
    193 
    194   // See class documentation for Widget in widget.h for a note about ownership.
    195   Widget::InitParams::Ownership ownership_;
    196 
    197   // The following factory is used for calls to close the NativeWidgetAura
    198   // instance.
    199   base::WeakPtrFactory<NativeWidgetAura> close_widget_factory_;
    200 
    201   // Can we be made active?
    202   bool can_activate_;
    203 
    204   // Are we in the destructor?
    205   bool destroying_;
    206 
    207   gfx::NativeCursor cursor_;
    208 
    209   // The saved window state for exiting full screen state.
    210   ui::WindowShowState saved_window_state_;
    211 
    212   scoped_ptr<TooltipManagerAura> tooltip_manager_;
    213 
    214   // Reorders child windows of |window_| associated with a view based on the
    215   // order of the associated views in the widget's view hierarchy.
    216   scoped_ptr<WindowReorderer> window_reorderer_;
    217 
    218   scoped_ptr<NativeWidgetAuraWindowObserver> active_window_observer_;
    219 
    220   scoped_ptr<DropHelper> drop_helper_;
    221   int last_drop_operation_;
    222 
    223   DISALLOW_COPY_AND_ASSIGN(NativeWidgetAura);
    224 };
    225 
    226 }  // namespace views
    227 
    228 #endif  // UI_VIEWS_WIDGET_NATIVE_WIDGET_AURA_H_
    229