OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "chrome/browser/tabs/tab_strip_model.h" | 11 #include "chrome/browser/tabs/tab_strip_model.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/panels/native_panel.h" | 13 #include "chrome/browser/ui/panels/native_panel.h" |
14 #include "chrome/browser/ui/panels/panel_manager.h" | 14 #include "chrome/browser/ui/panels/panel_manager.h" |
15 #include "chrome/browser/ui/panels/panel_overflow_strip.h" | |
jennb
2011/12/02 19:15:00
Don't need this.
jianli
2011/12/02 23:23:46
It is needed now after I added Panel::MoveOutOfOve
| |
16 #include "chrome/browser/ui/panels/panel_strip.h" | |
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
16 #include "chrome/browser/ui/window_sizer.h" | 18 #include "chrome/browser/ui/window_sizer.h" |
17 #include "chrome/browser/web_applications/web_app.h" | 19 #include "chrome/browser/web_applications/web_app.h" |
18 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
19 #include "content/browser/renderer_host/render_view_host.h" | 21 #include "content/browser/renderer_host/render_view_host.h" |
20 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
21 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
23 #include "content/public/browser/notification_types.h" | 25 #include "content/public/browser/notification_types.h" |
24 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 if (auto_resizable_) { | 118 if (auto_resizable_) { |
117 RenderViewHost* render_view_host = GetRenderViewHost(); | 119 RenderViewHost* render_view_host = GetRenderViewHost(); |
118 if (render_view_host) | 120 if (render_view_host) |
119 RequestRenderViewHostToDisableScrollbars(render_view_host); | 121 RequestRenderViewHostToDisableScrollbars(render_view_host); |
120 } | 122 } |
121 } | 123 } |
122 | 124 |
123 void Panel::SetExpansionState(ExpansionState new_state) { | 125 void Panel::SetExpansionState(ExpansionState new_state) { |
124 if (expansion_state_ == new_state) | 126 if (expansion_state_ == new_state) |
125 return; | 127 return; |
126 | |
127 ExpansionState old_state = expansion_state_; | 128 ExpansionState old_state = expansion_state_; |
128 expansion_state_ = new_state; | 129 expansion_state_ = new_state; |
129 | 130 |
130 int height; | 131 manager()->OnPanelExpansionStateChanged(this, old_state); |
131 switch (expansion_state_) { | |
132 case EXPANDED: | |
133 height = restored_size_.height(); | |
134 break; | |
135 case TITLE_ONLY: | |
136 height = native_panel_->TitleOnlyHeight(); | |
137 break; | |
138 case MINIMIZED: | |
139 height = kMinimizedPanelHeight; | |
140 break; | |
141 default: | |
142 NOTREACHED(); | |
143 height = restored_size_.height(); | |
144 break; | |
145 } | |
146 | |
147 int bottom = manager()->GetBottomPositionForExpansionState(expansion_state_); | |
148 gfx::Rect bounds = native_panel_->GetPanelBounds(); | |
149 bounds.set_y(bottom - height); | |
150 bounds.set_height(height); | |
151 SetPanelBounds(bounds); | |
152 | |
153 manager()->OnPanelExpansionStateChanged(old_state, new_state); | |
154 | 132 |
155 // The minimized panel should not get the focus. | 133 // The minimized panel should not get the focus. |
156 if (expansion_state_ == MINIMIZED) | 134 if (expansion_state_ == MINIMIZED) |
157 Deactivate(); | 135 Deactivate(); |
158 | 136 |
159 content::NotificationService::current()->Notify( | 137 content::NotificationService::current()->Notify( |
160 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, | 138 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, |
161 content::Source<Panel>(this), | 139 content::Source<Panel>(this), |
162 content::NotificationService::NoDetails()); | 140 content::NotificationService::NoDetails()); |
163 } | 141 } |
(...skipping 16 matching lines...) Expand all Loading... | |
180 gfx::Rect bounds = native_panel_->GetPanelBounds(); | 158 gfx::Rect bounds = native_panel_->GetPanelBounds(); |
181 return bounds.x() <= mouse_x && mouse_x <= bounds.right() && | 159 return bounds.x() <= mouse_x && mouse_x <= bounds.right() && |
182 mouse_y >= bounds.y(); | 160 mouse_y >= bounds.y(); |
183 } | 161 } |
184 | 162 |
185 bool Panel::IsDrawingAttention() const { | 163 bool Panel::IsDrawingAttention() const { |
186 return native_panel_->IsDrawingAttention(); | 164 return native_panel_->IsDrawingAttention(); |
187 } | 165 } |
188 | 166 |
189 void Panel::Show() { | 167 void Panel::Show() { |
190 native_panel_->ShowPanel(); | 168 // Don't show panel as active if it is in overflow state. |
169 if (expansion_state_ == IN_OVERFLOW) | |
170 native_panel_->ShowPanelInactive(); | |
jennb
2011/12/02 19:15:00
nit: call ShowInactive() rather than direct to nat
jianli
2011/12/02 23:23:46
Done.
| |
171 else | |
172 native_panel_->ShowPanel(); | |
191 } | 173 } |
192 | 174 |
193 void Panel::ShowInactive() { | 175 void Panel::ShowInactive() { |
194 native_panel_->ShowPanelInactive(); | 176 native_panel_->ShowPanelInactive(); |
195 } | 177 } |
196 | 178 |
197 void Panel::SetBounds(const gfx::Rect& bounds) { | 179 void Panel::SetBounds(const gfx::Rect& bounds) { |
198 // Ignore any SetBounds requests since the bounds are completely controlled | 180 // Ignore any SetBounds requests since the bounds are completely controlled |
199 // by panel manager. | 181 // by panel manager. |
200 } | 182 } |
201 | 183 |
202 // Close() may be called multiple times if the browser window is not ready to | 184 // Close() may be called multiple times if the browser window is not ready to |
203 // close on the first attempt. | 185 // close on the first attempt. |
204 void Panel::Close() { | 186 void Panel::Close() { |
205 native_panel_->ClosePanel(); | 187 native_panel_->ClosePanel(); |
206 } | 188 } |
207 | 189 |
208 void Panel::Activate() { | 190 void Panel::Activate() { |
191 // Don't activate the panel if it is in overflow state. | |
jennb
2011/12/02 19:15:00
Activate() is the way an app can force it's window
jianli
2011/12/02 23:23:46
Done. Called the newly added method MoveOutOfOverf
| |
192 if (expansion_state_ == IN_OVERFLOW) | |
193 return; | |
194 | |
209 // Make sure the panel is expanded when activated programmatically, | 195 // Make sure the panel is expanded when activated programmatically, |
210 // so the user input does not go into collapsed window. | 196 // so the user input does not go into collapsed window. |
211 SetExpansionState(Panel::EXPANDED); | 197 SetExpansionState(Panel::EXPANDED); |
212 native_panel_->ActivatePanel(); | 198 native_panel_->ActivatePanel(); |
213 } | 199 } |
214 | 200 |
215 void Panel::Deactivate() { | 201 void Panel::Deactivate() { |
216 native_panel_->DeactivatePanel(); | 202 native_panel_->DeactivatePanel(); |
217 } | 203 } |
218 | 204 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 bounds.set_y(bounds.bottom() - restored_size_.height()); | 255 bounds.set_y(bounds.bottom() - restored_size_.height()); |
270 bounds.set_x(bounds.right() - restored_size_.width()); | 256 bounds.set_x(bounds.right() - restored_size_.width()); |
271 bounds.set_size(restored_size_); | 257 bounds.set_size(restored_size_); |
272 return bounds; | 258 return bounds; |
273 } | 259 } |
274 | 260 |
275 gfx::Rect Panel::GetBounds() const { | 261 gfx::Rect Panel::GetBounds() const { |
276 return native_panel_->GetPanelBounds(); | 262 return native_panel_->GetPanelBounds(); |
277 } | 263 } |
278 | 264 |
265 int Panel::TitleOnlyHeight() const { | |
266 return native_panel_->TitleOnlyHeight(); | |
267 } | |
268 | |
269 gfx::Size Panel::IconOnlySize() const { | |
270 return native_panel_->IconOnlySize(); | |
271 } | |
272 | |
273 void Panel::EnsureFullyVisible() { | |
274 native_panel_->EnsurePanelFullyVisible(); | |
275 } | |
276 | |
279 bool Panel::IsMaximized() const { | 277 bool Panel::IsMaximized() const { |
280 // Size of panels is managed by PanelManager, they are never 'zoomed'. | 278 // Size of panels is managed by PanelManager, they are never 'zoomed'. |
281 return false; | 279 return false; |
282 } | 280 } |
283 | 281 |
284 bool Panel::IsMinimized() const { | 282 bool Panel::IsMinimized() const { |
285 return expansion_state_ != EXPANDED; | 283 return expansion_state_ != EXPANDED; |
286 } | 284 } |
287 | 285 |
288 void Panel::Maximize() { | 286 void Panel::Maximize() { |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
647 if (auto_resizable_) { | 645 if (auto_resizable_) { |
648 RenderViewHost* render_view_host = GetRenderViewHost(); | 646 RenderViewHost* render_view_host = GetRenderViewHost(); |
649 if (render_view_host) | 647 if (render_view_host) |
650 RequestRenderViewHostToDisableScrollbars(render_view_host); | 648 RequestRenderViewHostToDisableScrollbars(render_view_host); |
651 } | 649 } |
652 } | 650 } |
653 | 651 |
654 void Panel::DestroyBrowser() { | 652 void Panel::DestroyBrowser() { |
655 native_panel_->DestroyPanelBrowser(); | 653 native_panel_->DestroyPanelBrowser(); |
656 } | 654 } |
OLD | NEW |