Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / panels / panel_cocoa.h
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_COCOA_PANELS_PANEL_COCOA_H_
6 #define CHROME_BROWSER_UI_COCOA_PANELS_PANEL_COCOA_H_
7
8 #import <Foundation/Foundation.h>
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/ui/panels/native_panel.h"
11 #include "ui/gfx/rect.h"
12
13 class Panel;
14 @class PanelWindowControllerCocoa;
15
16 // An implememtation of the native panel in Cocoa.
17 // Bridges between C++ and the Cocoa NSWindow. Cross-platform code will
18 // interact with this object when it needs to manipulate the window.
19 class PanelCocoa : public NativePanel {
20  public:
21   PanelCocoa(Panel* panel, const gfx::Rect& bounds, bool always_on_top);
22   ~PanelCocoa() override;
23
24   // Overridden from NativePanel
25   void ShowPanel() override;
26   void ShowPanelInactive() override;
27   gfx::Rect GetPanelBounds() const override;
28   void SetPanelBounds(const gfx::Rect& bounds) override;
29   void SetPanelBoundsInstantly(const gfx::Rect& bounds) override;
30   void ClosePanel() override;
31   void ActivatePanel() override;
32   void DeactivatePanel() override;
33   bool IsPanelActive() const override;
34   void PreventActivationByOS(bool prevent_activation) override;
35   gfx::NativeWindow GetNativePanelWindow() override;
36   void UpdatePanelTitleBar() override;
37   void UpdatePanelLoadingAnimations(bool should_animate) override;
38   void PanelWebContentsFocused(content::WebContents* contents) override;
39   void PanelCut() override;
40   void PanelCopy() override;
41   void PanelPaste() override;
42   void DrawAttention(bool draw_attention) override;
43   bool IsDrawingAttention() const override;
44   void HandlePanelKeyboardEvent(
45       const content::NativeWebKeyboardEvent& event) override;
46   void FullScreenModeChanged(bool is_full_screen) override;
47   bool IsPanelAlwaysOnTop() const override;
48   void SetPanelAlwaysOnTop(bool on_top) override;
49   void UpdatePanelMinimizeRestoreButtonVisibility() override;
50   void SetWindowCornerStyle(panel::CornerStyle corner_style) override;
51   void PanelExpansionStateChanging(Panel::ExpansionState old_state,
52                                    Panel::ExpansionState new_state) override;
53   void AttachWebContents(content::WebContents* contents) override;
54   void DetachWebContents(content::WebContents* contents) override;
55
56   // These sizes are in screen coordinates.
57   gfx::Size WindowSizeFromContentSize(
58       const gfx::Size& content_size) const override;
59   gfx::Size ContentSizeFromWindowSize(
60       const gfx::Size& window_size) const override;
61   int TitleOnlyHeight() const override;
62
63   void MinimizePanelBySystem() override;
64   bool IsPanelMinimizedBySystem() const override;
65   bool IsPanelShownOnActiveDesktop() const override;
66   void ShowShadow(bool show) override;
67   NativePanelTesting* CreateNativePanelTesting() override;
68
69   Panel* panel() const;
70   void DidCloseNativeWindow();
71
72   bool IsClosed() const;
73
74   // PanelStackWindowCocoa might want to update the stored bounds directly since
75   // it has already taken care of updating the window bounds directly.
76   void set_cached_bounds_directly(const gfx::Rect& bounds) { bounds_ = bounds; }
77
78  private:
79   friend class CocoaNativePanelTesting;
80   friend class PanelCocoaTest;
81   FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, CreateClose);
82   FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, NativeBounds);
83   FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, TitlebarViewCreate);
84   FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, TitlebarViewSizing);
85   FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, TitlebarViewClose);
86   FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, MenuItems);
87   FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, KeyEvent);
88   FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, ThemeProvider);
89   FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, SetTitle);
90   FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, ActivatePanel);
91
92   void setBoundsInternal(const gfx::Rect& bounds, bool animate);
93
94   scoped_ptr<Panel> panel_;
95   PanelWindowControllerCocoa* controller_;  // Weak, owns us.
96
97   // These use platform-independent screen coordinates, with (0,0) at
98   // top-left of the primary screen. They have to be converted to Cocoa
99   // screen coordinates before calling Cocoa API.
100   gfx::Rect bounds_;
101
102   // True if the panel should always stay on top of other windows.
103   bool always_on_top_;
104
105   bool is_shown_;  // Panel is hidden on creation, Show() changes that forever.
106   NSInteger attention_request_id_;  // identifier from requestUserAttention.
107
108   // Indicates how the window corner should be rendered, rounded or not.
109   panel::CornerStyle corner_style_;
110
111   DISALLOW_COPY_AND_ASSIGN(PanelCocoa);
112 };
113
114 #endif  // CHROME_BROWSER_UI_COCOA_PANELS_PANEL_COCOA_H_