OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/panels/panel.h" | 5 #include "chrome/browser/ui/panels/panel.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/extensions/extension_prefs.h" | 8 #include "chrome/browser/extensions/extension_prefs.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); | 41 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); |
42 } | 42 } |
43 | 43 |
44 Panel::Panel(Browser* browser, const gfx::Size& requested_size) | 44 Panel::Panel(Browser* browser, const gfx::Size& requested_size) |
45 : browser_(browser), | 45 : browser_(browser), |
46 initialized_(false), | 46 initialized_(false), |
47 has_temporary_layout_(false), | 47 has_temporary_layout_(false), |
48 restored_size_(requested_size), | 48 restored_size_(requested_size), |
49 auto_resizable_(false), | 49 auto_resizable_(false), |
50 draggable_(true), | 50 draggable_(true), |
51 layout_state_(DOCKED), | |
51 expansion_state_(EXPANDED), | 52 expansion_state_(EXPANDED), |
52 old_expansion_state_(EXPANDED), | |
53 app_icon_visible_(true) { | 53 app_icon_visible_(true) { |
54 } | 54 } |
55 | 55 |
56 Panel::~Panel() { | 56 Panel::~Panel() { |
57 // Invoked by native panel destructor. Do not access native_panel_ here. | 57 // Invoked by native panel destructor. Do not access native_panel_ here. |
58 } | 58 } |
59 | 59 |
60 void Panel::Initialize(const gfx::Rect& bounds) { | 60 void Panel::Initialize(const gfx::Rect& bounds) { |
61 DCHECK(!initialized_); | 61 DCHECK(!initialized_); |
62 DCHECK(!bounds.IsEmpty()); | 62 DCHECK(!bounds.IsEmpty()); |
63 initialized_ = true; | 63 initialized_ = true; |
64 native_panel_ = CreateNativePanel(browser_, this, bounds); | 64 native_panel_ = CreateNativePanel(browser_, this, bounds); |
65 } | 65 } |
66 | 66 |
67 void Panel::OnNativePanelClosed() { | 67 void Panel::OnNativePanelClosed() { |
68 if (auto_resizable_) | 68 if (auto_resizable_) |
69 native_panel_->GetPanelBrowser()->tabstrip_model()->RemoveObserver(this); | 69 native_panel_->GetPanelBrowser()->tabstrip_model()->RemoveObserver(this); |
70 manager()->Remove(this); | 70 manager()->Remove(this); |
71 } | 71 } |
72 | 72 |
73 PanelManager* Panel::manager() const { | 73 PanelManager* Panel::manager() const { |
74 return PanelManager::GetInstance(); | 74 return PanelManager::GetInstance(); |
75 } | 75 } |
76 | 76 |
77 const Extension* Panel::GetExtension() const { | 77 const Extension* Panel::GetExtension() const { |
78 return GetExtensionFromBrowser(browser()); | 78 return GetExtensionFromBrowser(browser()); |
79 } | 79 } |
80 | 80 |
81 void Panel::SetPanelBounds(const gfx::Rect& bounds) { | 81 void Panel::SetPanelBounds(const gfx::Rect& bounds) { |
82 if (expansion_state_ == Panel::EXPANDED) | 82 if (layout_state_ == DOCKED && expansion_state_ == EXPANDED) |
jennb
2012/01/19 23:44:09
should be layout state != IN_OVERFLOW? (I can see
jianli
2012/01/20 01:16:07
Done.
| |
83 restored_size_ = bounds.size(); | 83 restored_size_ = bounds.size(); |
84 | 84 |
85 native_panel_->SetPanelBounds(bounds); | 85 native_panel_->SetPanelBounds(bounds); |
86 | 86 |
87 content::NotificationService::current()->Notify( | 87 content::NotificationService::current()->Notify( |
88 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS, | 88 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS, |
89 content::Source<Panel>(this), | 89 content::Source<Panel>(this), |
90 content::NotificationService::NoDetails()); | 90 content::NotificationService::NoDetails()); |
91 } | 91 } |
92 | 92 |
93 void Panel::SetPanelBoundsInstantly(const gfx::Rect& bounds) { | 93 void Panel::SetPanelBoundsInstantly(const gfx::Rect& bounds) { |
94 if (expansion_state_ == Panel::EXPANDED) | 94 if (layout_state_ == DOCKED && expansion_state_ == EXPANDED) |
jennb
2012/01/19 23:44:09
Ditto
jianli
2012/01/20 01:16:07
Done.
| |
95 restored_size_ = bounds.size(); | 95 restored_size_ = bounds.size(); |
96 | 96 |
97 native_panel_->SetPanelBoundsInstantly(bounds); | 97 native_panel_->SetPanelBoundsInstantly(bounds); |
98 | 98 |
99 content::NotificationService::current()->Notify( | 99 content::NotificationService::current()->Notify( |
100 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS, | 100 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS, |
101 content::Source<Panel>(this), | 101 content::Source<Panel>(this), |
102 content::NotificationService::NoDetails()); | 102 content::NotificationService::NoDetails()); |
103 } | 103 } |
104 | 104 |
(...skipping 25 matching lines...) Expand all Loading... | |
130 ConfigureAutoResize(browser()->GetSelectedWebContents()); | 130 ConfigureAutoResize(browser()->GetSelectedWebContents()); |
131 } | 131 } |
132 | 132 |
133 void Panel::SetAppIconVisibility(bool visible) { | 133 void Panel::SetAppIconVisibility(bool visible) { |
134 if (app_icon_visible_ == visible) | 134 if (app_icon_visible_ == visible) |
135 return; | 135 return; |
136 app_icon_visible_ = visible; | 136 app_icon_visible_ = visible; |
137 native_panel_->SetPanelAppIconVisibility(visible); | 137 native_panel_->SetPanelAppIconVisibility(visible); |
138 } | 138 } |
139 | 139 |
140 void Panel::SetLayoutState(LayoutState new_state) { | |
141 if (layout_state_ == new_state) | |
142 return; | |
143 LayoutState old_state = layout_state_; | |
144 layout_state_ = new_state; | |
145 | |
146 manager()->OnPanelLayoutStateChanged(this, old_state); | |
147 | |
148 content::NotificationService::current()->Notify( | |
149 chrome::NOTIFICATION_PANEL_CHANGED_LAYOUT_STATE, | |
150 content::Source<Panel>(this), | |
151 content::NotificationService::NoDetails()); | |
152 } | |
153 | |
140 void Panel::SetExpansionState(ExpansionState new_state) { | 154 void Panel::SetExpansionState(ExpansionState new_state) { |
141 if (expansion_state_ == new_state) | 155 if (expansion_state_ == new_state) |
142 return; | 156 return; |
143 old_expansion_state_ = expansion_state_; | 157 ExpansionState old_state = expansion_state_; |
144 expansion_state_ = new_state; | 158 expansion_state_ = new_state; |
145 | 159 |
146 manager()->OnPanelExpansionStateChanged(this); | 160 manager()->OnPanelExpansionStateChanged(this, old_state); |
147 | 161 |
148 // The minimized panel should not get the focus. | 162 // The minimized panel should not get the focus. |
149 if (expansion_state_ == MINIMIZED) | 163 if (expansion_state_ == MINIMIZED && layout_state_ == DOCKED) |
150 Deactivate(); | 164 Deactivate(); |
151 | 165 |
152 content::NotificationService::current()->Notify( | 166 content::NotificationService::current()->Notify( |
153 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, | 167 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, |
154 content::Source<Panel>(this), | 168 content::Source<Panel>(this), |
155 content::NotificationService::NoDetails()); | 169 content::NotificationService::NoDetails()); |
156 } | 170 } |
157 | 171 |
158 bool Panel::IsDrawingAttention() const { | 172 bool Panel::IsDrawingAttention() const { |
159 return native_panel_->IsDrawingAttention(); | 173 return native_panel_->IsDrawingAttention(); |
160 } | 174 } |
161 | 175 |
162 void Panel::FullScreenModeChanged(bool is_full_screen) { | 176 void Panel::FullScreenModeChanged(bool is_full_screen) { |
163 native_panel_->FullScreenModeChanged(is_full_screen); | 177 native_panel_->FullScreenModeChanged(is_full_screen); |
164 } | 178 } |
165 | 179 |
166 void Panel::Show() { | 180 void Panel::Show() { |
167 // Don't show panel as active if it is in overflow state. | 181 // Don't show panel as active if it is in overflow state. |
168 if (expansion_state_ == IN_OVERFLOW) | 182 if (layout_state_ == IN_OVERFLOW) |
169 ShowInactive(); | 183 ShowInactive(); |
170 else | 184 else |
171 native_panel_->ShowPanel(); | 185 native_panel_->ShowPanel(); |
172 } | 186 } |
173 | 187 |
174 void Panel::ShowInactive() { | 188 void Panel::ShowInactive() { |
175 native_panel_->ShowPanelInactive(); | 189 native_panel_->ShowPanelInactive(); |
176 } | 190 } |
177 | 191 |
178 void Panel::SetBounds(const gfx::Rect& bounds) { | 192 void Panel::SetBounds(const gfx::Rect& bounds) { |
179 // Ignore bounds position as the panel manager controls all positioning. | 193 // Ignore bounds position as the panel manager controls all positioning. |
180 manager()->ResizePanel(this, bounds.size()); | 194 manager()->ResizePanel(this, bounds.size()); |
181 } | 195 } |
182 | 196 |
183 // Close() may be called multiple times if the browser window is not ready to | 197 // Close() may be called multiple times if the browser window is not ready to |
184 // close on the first attempt. | 198 // close on the first attempt. |
185 void Panel::Close() { | 199 void Panel::Close() { |
186 native_panel_->ClosePanel(); | 200 native_panel_->ClosePanel(); |
187 } | 201 } |
188 | 202 |
189 void Panel::Activate() { | 203 void Panel::Activate() { |
190 // Make sure the panel is expanded when activated programmatically, | 204 // Make sure the panel is expanded when activated programmatically, |
191 // so the user input does not go into collapsed window. | 205 // so the user input does not go into collapsed window. |
192 SetExpansionState(Panel::EXPANDED); | 206 SetExpansionState(Panel::EXPANDED); |
207 SetLayoutState(Panel::DOCKED); | |
193 native_panel_->ActivatePanel(); | 208 native_panel_->ActivatePanel(); |
194 } | 209 } |
195 | 210 |
196 void Panel::Deactivate() { | 211 void Panel::Deactivate() { |
197 native_panel_->DeactivatePanel(); | 212 native_panel_->DeactivatePanel(); |
198 } | 213 } |
199 | 214 |
200 bool Panel::IsActive() const { | 215 bool Panel::IsActive() const { |
201 return native_panel_->IsPanelActive(); | 216 return native_panel_->IsPanelActive(); |
202 } | 217 } |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 native_panel_->ContentSizeFromWindowSize(max_size_)); | 660 native_panel_->ContentSizeFromWindowSize(max_size_)); |
646 } | 661 } |
647 | 662 |
648 void Panel::OnWindowSizeAvailable() { | 663 void Panel::OnWindowSizeAvailable() { |
649 ConfigureAutoResize(browser()->GetSelectedWebContents()); | 664 ConfigureAutoResize(browser()->GetSelectedWebContents()); |
650 } | 665 } |
651 | 666 |
652 void Panel::DestroyBrowser() { | 667 void Panel::DestroyBrowser() { |
653 native_panel_->DestroyPanelBrowser(); | 668 native_panel_->DestroyPanelBrowser(); |
654 } | 669 } |
OLD | NEW |