1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_WINDOW_COCOA_H_
#define CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_WINDOW_COCOA_H_
#import <Foundation/Foundation.h>
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/panels/native_panel_cocoa.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/gfx/rect.h"
class Browser;
class Panel;
@class PanelWindowControllerCocoa;
// An implementation of BrowserWindow for native Panel in Cocoa.
// Bridges between C++ and the Cocoa NSWindow. Cross-platform code will
// interact with this object when it needs to manipulate the window.
class PanelBrowserWindowCocoa : public NativePanelCocoa,
public TabStripModelObserver,
public content::NotificationObserver {
public:
PanelBrowserWindowCocoa(Browser* browser, Panel* panel,
const gfx::Rect& bounds);
virtual ~PanelBrowserWindowCocoa();
// Overridden from NativePanel
virtual void ShowPanel() OVERRIDE;
virtual void ShowPanelInactive() OVERRIDE;
virtual gfx::Rect GetPanelBounds() const OVERRIDE;
virtual void SetPanelBounds(const gfx::Rect& bounds) OVERRIDE;
virtual void SetPanelBoundsInstantly(const gfx::Rect& bounds) OVERRIDE;
virtual void ClosePanel() OVERRIDE;
virtual void ActivatePanel() OVERRIDE;
virtual void DeactivatePanel() OVERRIDE;
virtual bool IsPanelActive() const OVERRIDE;
virtual void PreventActivationByOS(bool prevent_activation) OVERRIDE;
virtual gfx::NativeWindow GetNativePanelHandle() OVERRIDE;
virtual void UpdatePanelTitleBar() OVERRIDE;
virtual void UpdatePanelLoadingAnimations(bool should_animate) OVERRIDE;
virtual void ShowTaskManagerForPanel() OVERRIDE;
virtual FindBar* CreatePanelFindBar() OVERRIDE;
virtual void NotifyPanelOnUserChangedTheme() OVERRIDE;
virtual void PanelWebContentsFocused(content::WebContents* contents) OVERRIDE;
virtual void PanelCut() OVERRIDE;
virtual void PanelCopy() OVERRIDE;
virtual void PanelPaste() OVERRIDE;
virtual void DrawAttention(bool draw_attention) OVERRIDE;
virtual bool IsDrawingAttention() const OVERRIDE;
virtual bool PreHandlePanelKeyboardEvent(
const content::NativeWebKeyboardEvent& event,
bool* is_keyboard_shortcut) OVERRIDE;
virtual void HandlePanelKeyboardEvent(
const content::NativeWebKeyboardEvent& event) OVERRIDE;
virtual void FullScreenModeChanged(bool is_full_screen) OVERRIDE;
virtual Browser* GetPanelBrowser() const OVERRIDE;
virtual void DestroyPanelBrowser() OVERRIDE;
virtual void EnsurePanelFullyVisible() OVERRIDE;
virtual void SetPanelAlwaysOnTop(bool on_top) OVERRIDE;
virtual void EnableResizeByMouse(bool enable) OVERRIDE;
virtual void UpdatePanelMinimizeRestoreButtonVisibility() OVERRIDE;
virtual void PanelExpansionStateChanging(
Panel::ExpansionState old_state,
Panel::ExpansionState new_state) OVERRIDE;
virtual NativePanelTesting* CreateNativePanelTesting() OVERRIDE;
// These sizes are in screen coordinates.
virtual gfx::Size WindowSizeFromContentSize(
const gfx::Size& content_size) const OVERRIDE;
virtual gfx::Size ContentSizeFromWindowSize(
const gfx::Size& window_size) const OVERRIDE;
virtual int TitleOnlyHeight() const OVERRIDE;
// Overridden from TabStripModelObserver.
virtual void TabInsertedAt(TabContents* contents,
int index,
bool foreground) OVERRIDE;
virtual void TabDetachedAt(TabContents* contents, int index) OVERRIDE;
// Overridden from NotificationObserver.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// Overridden from NativePanelCocoa.
virtual Panel* panel() const OVERRIDE;
virtual void DidCloseNativeWindow() OVERRIDE;
private:
friend class PanelBrowserWindowCocoaTest;
friend class NativePanelTestingCocoa;
FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, CreateClose);
FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, NativeBounds);
FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, TitlebarViewCreate);
FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, TitlebarViewSizing);
FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, TitlebarViewClose);
FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, MenuItems);
FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, KeyEvent);
FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, ThemeProvider);
FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, SetTitle);
FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, ActivatePanel);
bool isClosed();
void setBoundsInternal(const gfx::Rect& bounds, bool animate);
scoped_ptr<Browser> browser_;
scoped_ptr<Panel> panel_;
// These use platform-independent screen coordinates, with (0,0) at
// top-left of the primary screen. They have to be converted to Cocoa
// screen coordinates before calling Cocoa API.
gfx::Rect bounds_;
PanelWindowControllerCocoa* controller_; // Weak, owns us.
bool is_shown_; // Panel is hidden on creation, Show() changes that forever.
bool has_find_bar_; // Find bar should only be created once per panel.
NSInteger attention_request_id_; // identifier from requestUserAttention.
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(PanelBrowserWindowCocoa);
};
#endif // CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_WINDOW_COCOA_H_
|