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_DELEGATE_H_
      6 #define UI_VIEWS_WIDGET_NATIVE_WIDGET_DELEGATE_H_
      7 
      8 #include <vector>
      9 
     10 #include "ui/base/events/event_constants.h"
     11 #include "ui/views/views_export.h"
     12 
     13 namespace gfx {
     14 class Canvas;
     15 class Path;
     16 class Point;
     17 class Size;
     18 }
     19 
     20 namespace ui {
     21 class GestureEvent;
     22 class KeyEvent;
     23 class Layer;
     24 class MouseEvent;
     25 class TouchEvent;
     26 class ScrollEvent;
     27 }
     28 
     29 namespace views {
     30 class InputMethod;
     31 class Widget;
     32 
     33 namespace internal {
     34 
     35 ////////////////////////////////////////////////////////////////////////////////
     36 // NativeWidgetDelegate
     37 //
     38 //  An interface implemented by the object that handles events sent by a
     39 //  NativeWidget implementation.
     40 //
     41 class VIEWS_EXPORT NativeWidgetDelegate {
     42  public:
     43   virtual ~NativeWidgetDelegate() {}
     44 
     45   // Returns true if the window is modal.
     46   virtual bool IsModal() const = 0;
     47 
     48   // Returns true if the window is a dialog box.
     49   virtual bool IsDialogBox() const = 0;
     50 
     51   // Returns true if the window can be activated.
     52   virtual bool CanActivate() const = 0;
     53 
     54   virtual bool IsInactiveRenderingDisabled() const = 0;
     55   virtual void EnableInactiveRendering() = 0;
     56 
     57   // Called when the activation state of a window has changed.
     58   virtual void OnNativeWidgetActivationChanged(bool active) = 0;
     59 
     60   // Called when native focus moves from one native view to another.
     61   virtual void OnNativeFocus(gfx::NativeView focused_view) = 0;
     62   virtual void OnNativeBlur(gfx::NativeView focused_view) = 0;
     63 
     64   // Called when the window is shown/hidden.
     65   virtual void OnNativeWidgetVisibilityChanged(bool visible) = 0;
     66 
     67   // Called when the native widget is created.
     68   // The |desktop_widget| bool is true for widgets created in the desktop and
     69   // false for widgets created in the shell.
     70   virtual void OnNativeWidgetCreated(bool desktop_widget) = 0;
     71 
     72   // Called just before the native widget is destroyed. This is the delegate's
     73   // last chance to do anything with the native widget handle.
     74   virtual void OnNativeWidgetDestroying() = 0;
     75 
     76   // Called just after the native widget is destroyed.
     77   virtual void OnNativeWidgetDestroyed() = 0;
     78 
     79   // Returns the smallest size the window can be resized to by the user.
     80   virtual gfx::Size GetMinimumSize() = 0;
     81 
     82   // Returns the largest size the window can be resized to by the user.
     83   virtual gfx::Size GetMaximumSize() = 0;
     84 
     85   // Called when the NativeWidget changed position.
     86   virtual void OnNativeWidgetMove() = 0;
     87 
     88   // Called when the NativeWidget changed size to |new_size|.
     89   virtual void OnNativeWidgetSizeChanged(const gfx::Size& new_size) = 0;
     90 
     91   // Called when the user begins/ends to change the bounds of the window.
     92   virtual void OnNativeWidgetBeginUserBoundsChange() = 0;
     93   virtual void OnNativeWidgetEndUserBoundsChange() = 0;
     94 
     95   // Returns true if the delegate has a FocusManager.
     96   virtual bool HasFocusManager() const = 0;
     97 
     98   // Paints the widget using acceleration. If the widget is not using
     99   // accelerated painting this returns false and does nothing.
    100   virtual bool OnNativeWidgetPaintAccelerated(
    101       const gfx::Rect& dirty_region) = 0;
    102 
    103   // Paints the rootview in the canvas. This will also refresh the compositor
    104   // tree if necessary when accelerated painting is enabled.
    105   virtual void OnNativeWidgetPaint(gfx::Canvas* canvas) = 0;
    106 
    107   // Returns the non-client component (see ui/base/hit_test.h) containing
    108   // |point|, in client coordinates.
    109   virtual int GetNonClientComponent(const gfx::Point& point) = 0;
    110 
    111   // Mouse and key event handlers.
    112   virtual void OnKeyEvent(ui::KeyEvent* event) = 0;
    113   virtual void OnMouseEvent(ui::MouseEvent* event) = 0;
    114   virtual void OnMouseCaptureLost() = 0;
    115 
    116   virtual void OnTouchEvent(ui::TouchEvent* event) = 0;
    117   virtual void OnScrollEvent(ui::ScrollEvent* event) = 0;
    118   virtual void OnGestureEvent(ui::GestureEvent* event) = 0;
    119 
    120   // Runs the specified native command. Returns true if the command is handled.
    121   virtual bool ExecuteCommand(int command_id) = 0;
    122 
    123   // Returns the input method of the widget this delegate is associated with.
    124   // Note that this does not use the top level widget, so may return NULL
    125   // if the widget doesn't have input method.
    126   virtual InputMethod* GetInputMethodDirect() = 0;
    127 
    128   // Returns the child Layers of the Widgets layer that were created by Views.
    129   virtual const std::vector<ui::Layer*>& GetRootLayers() = 0;
    130 
    131   // Returns true if window has a hit-test mask.
    132   virtual bool HasHitTestMask() const = 0;
    133 
    134   // Provides the hit-test mask if HasHitTestMask above returns true.
    135   virtual void GetHitTestMask(gfx::Path* mask) const = 0;
    136 
    137   //
    138   virtual Widget* AsWidget() = 0;
    139   virtual const Widget* AsWidget() const = 0;
    140 };
    141 
    142 }  // namespace internal
    143 }  // namespace views
    144 
    145 #endif  // UI_VIEWS_WIDGET_NATIVE_WIDGET_DELEGATE_H_
    146