Home | History | Annotate | Download | only in panels
      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 CHROME_BROWSER_UI_PANELS_NATIVE_PANEL_H_
      6 #define CHROME_BROWSER_UI_PANELS_NATIVE_PANEL_H_
      7 
      8 #include "chrome/browser/ui/panels/panel.h"
      9 #include "chrome/browser/ui/panels/panel_constants.h"
     10 #include "ui/gfx/native_widget_types.h"
     11 
     12 class NativePanelTesting;
     13 
     14 namespace content {
     15 struct NativeWebKeyboardEvent;
     16 class WebContents;
     17 }
     18 
     19 namespace gfx {
     20 class Rect;
     21 }  // namespace gfx
     22 
     23 // An interface for a class that implements platform-specific behavior for panel
     24 // windows to provide additional methods not found in ui::BaseWindow.
     25 class NativePanel {
     26   friend class BasePanelBrowserTest;  // for CreateNativePanelTesting
     27   friend class Panel;
     28   friend class PanelBrowserWindow;
     29   friend class PanelBrowserTest;
     30   friend class PanelExtensionBrowserTest;
     31 
     32  protected:
     33   virtual ~NativePanel() {}
     34 
     35   virtual void ShowPanel() = 0;
     36   virtual void ShowPanelInactive() = 0;
     37   virtual gfx::Rect GetPanelBounds() const = 0;
     38   virtual void SetPanelBounds(const gfx::Rect& bounds) = 0;
     39   virtual void SetPanelBoundsInstantly(const gfx::Rect& bounds) = 0;
     40   virtual void ClosePanel() = 0;
     41   virtual void ActivatePanel() = 0;
     42   virtual void DeactivatePanel() = 0;
     43   virtual bool IsPanelActive() const = 0;
     44   virtual void PreventActivationByOS(bool prevent_activation) = 0;
     45   virtual gfx::NativeWindow GetNativePanelWindow() = 0;
     46   virtual void UpdatePanelTitleBar() = 0;
     47   virtual void UpdatePanelLoadingAnimations(bool should_animate) = 0;
     48   virtual void PanelWebContentsFocused(content::WebContents* contents) = 0;
     49   virtual void PanelCut() = 0;
     50   virtual void PanelCopy() = 0;
     51   virtual void PanelPaste() = 0;
     52   virtual void DrawAttention(bool draw_attention) = 0;
     53   virtual bool IsDrawingAttention() const = 0;
     54   virtual void HandlePanelKeyboardEvent(
     55       const content::NativeWebKeyboardEvent& event) = 0;
     56   virtual void FullScreenModeChanged(bool is_full_screen) = 0;
     57   virtual void PanelExpansionStateChanging(Panel::ExpansionState old_state,
     58                                            Panel::ExpansionState new_state) = 0;
     59   virtual void AttachWebContents(content::WebContents* contents) = 0;
     60   virtual void DetachWebContents(content::WebContents* contents) = 0;
     61 
     62   // Returns the exterior size of the panel window given the client content
     63   // size and vice versa.
     64   virtual gfx::Size WindowSizeFromContentSize(
     65       const gfx::Size& content_size) const = 0;
     66   virtual gfx::Size ContentSizeFromWindowSize(
     67       const gfx::Size& window_size) const = 0;
     68 
     69   virtual int TitleOnlyHeight() const = 0;
     70 
     71   // Gets or sets whether the panel window is always on top.
     72   virtual bool IsPanelAlwaysOnTop() const = 0;
     73   virtual void SetPanelAlwaysOnTop(bool on_top) = 0;
     74 
     75   // Enables resizing by dragging edges/corners.
     76   virtual void EnableResizeByMouse(bool enable) = 0;
     77 
     78   // Updates the visibility of the minimize and restore buttons.
     79   virtual void UpdatePanelMinimizeRestoreButtonVisibility() = 0;
     80 
     81   // Sets how the panel window displays its 4 corners, rounded or not.
     82   virtual void SetWindowCornerStyle(panel::CornerStyle corner_style) = 0;
     83 
     84   // Performs the system minimize for the panel, i.e. becoming iconic.
     85   virtual void MinimizePanelBySystem() = 0;
     86 
     87   // Returns true if the panel has been minimized by the system, i.e. becoming
     88   // iconic.
     89   virtual bool IsPanelMinimizedBySystem() const = 0;
     90 
     91   // Returns true if the panel is shown in the active desktop. The user could
     92   // create and use multiple virtual desktops or workspaces.
     93   virtual bool IsPanelShownOnActiveDesktop() const = 0;
     94 
     95   // Turns on/off the shadow effect around the window shape.
     96   virtual void ShowShadow(bool show) = 0;
     97 
     98   // Create testing interface for native panel. (Keep this last to separate
     99   // it from regular API.)
    100   virtual NativePanelTesting* CreateNativePanelTesting() = 0;
    101 };
    102 
    103 // A NativePanel utility interface used for accessing elements of the
    104 // native panel used only by test automation.
    105 class NativePanelTesting {
    106  public:
    107   virtual ~NativePanelTesting() {}
    108 
    109   // Wrappers for the common cases when no modifier is needed.
    110   void PressLeftMouseButtonTitlebar(const gfx::Point& mouse_location) {
    111     PressLeftMouseButtonTitlebar(mouse_location, panel::NO_MODIFIER);
    112   }
    113   void ReleaseMouseButtonTitlebar() {
    114     ReleaseMouseButtonTitlebar(panel::NO_MODIFIER);
    115   }
    116 
    117   // |mouse_location| is in screen coordinates.
    118   virtual void PressLeftMouseButtonTitlebar(
    119       const gfx::Point& mouse_location, panel::ClickModifier modifier) = 0;
    120   virtual void ReleaseMouseButtonTitlebar(panel::ClickModifier modifier) = 0;
    121   virtual void DragTitlebar(const gfx::Point& mouse_location) = 0;
    122   virtual void CancelDragTitlebar() = 0;
    123   virtual void FinishDragTitlebar() = 0;
    124 
    125   // Verifies, on a deepest possible level, if the Panel is showing the "Draw
    126   // Attention" effects to the user. May include checking colors etc.
    127   virtual bool VerifyDrawingAttention() const = 0;
    128   // Verifies, on a deepest possible level, if the native panel is really
    129   // active, i.e. the titlebar is painted per its active state.
    130   virtual bool VerifyActiveState(bool is_active) = 0;
    131   // Verifies, on a deepest possible level, if the native panel is really
    132   // showing a correct app icon (taskbar icon).
    133   virtual bool VerifyAppIcon() const = 0;
    134   // Verifies, on a deepest possible level, if the native panel is really
    135   // minimized by the system.
    136   virtual bool VerifySystemMinimizeState() const = 0;
    137 
    138   virtual bool IsWindowSizeKnown() const = 0;
    139   virtual bool IsAnimatingBounds() const = 0;
    140   virtual bool IsButtonVisible(panel::TitlebarButtonType button_type) const = 0;
    141 
    142   virtual panel::CornerStyle GetWindowCornerStyle() const = 0;
    143 
    144   // Makes sure that the application is running on foreground. Returns false
    145   // if the effort fails.
    146   virtual bool EnsureApplicationRunOnForeground() = 0;
    147 };
    148 
    149 #endif  // CHROME_BROWSER_UI_PANELS_NATIVE_PANEL_H_
    150