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