| 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 <vector> |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "chrome/browser/extensions/extension_prefs.h" | 9 #include "chrome/browser/extensions/extension_prefs.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/tabs/tab_strip_model.h" | 12 #include "chrome/browser/tabs/tab_strip_model.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/panels/native_panel.h" | 14 #include "chrome/browser/ui/panels/native_panel.h" |
| 14 #include "chrome/browser/ui/panels/panel_manager.h" | 15 #include "chrome/browser/ui/panels/panel_manager.h" |
| 16 #include "chrome/browser/ui/panels/panel_overflow_strip.h" |
| 17 #include "chrome/browser/ui/panels/panel_strip.h" |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 16 #include "chrome/browser/ui/window_sizer.h" | 19 #include "chrome/browser/ui/window_sizer.h" |
| 17 #include "chrome/browser/web_applications/web_app.h" | 20 #include "chrome/browser/web_applications/web_app.h" |
| 18 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
| 19 #include "content/browser/renderer_host/render_view_host.h" | 22 #include "content/browser/renderer_host/render_view_host.h" |
| 20 #include "content/browser/tab_contents/tab_contents.h" | 23 #include "content/browser/tab_contents/tab_contents.h" |
| 21 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 22 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
| 23 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
| 24 #include "ui/gfx/rect.h" | 27 #include "ui/gfx/rect.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 DCHECK(min_size.height() <= max_size.height()); | 117 DCHECK(min_size.height() <= max_size.height()); |
| 115 min_size_ = min_size; | 118 min_size_ = min_size; |
| 116 max_size_ = max_size; | 119 max_size_ = max_size; |
| 117 | 120 |
| 118 ConfigureAutoResize(browser()->GetSelectedTabContents()); | 121 ConfigureAutoResize(browser()->GetSelectedTabContents()); |
| 119 } | 122 } |
| 120 | 123 |
| 121 void Panel::SetExpansionState(ExpansionState new_state) { | 124 void Panel::SetExpansionState(ExpansionState new_state) { |
| 122 if (expansion_state_ == new_state) | 125 if (expansion_state_ == new_state) |
| 123 return; | 126 return; |
| 124 | |
| 125 ExpansionState old_state = expansion_state_; | 127 ExpansionState old_state = expansion_state_; |
| 126 expansion_state_ = new_state; | 128 expansion_state_ = new_state; |
| 127 | 129 |
| 128 int height; | 130 manager()->OnPanelExpansionStateChanged(this, old_state); |
| 129 switch (expansion_state_) { | |
| 130 case EXPANDED: | |
| 131 height = restored_size_.height(); | |
| 132 break; | |
| 133 case TITLE_ONLY: | |
| 134 height = native_panel_->TitleOnlyHeight(); | |
| 135 break; | |
| 136 case MINIMIZED: | |
| 137 height = kMinimizedPanelHeight; | |
| 138 break; | |
| 139 default: | |
| 140 NOTREACHED(); | |
| 141 height = restored_size_.height(); | |
| 142 break; | |
| 143 } | |
| 144 | |
| 145 int bottom = manager()->GetBottomPositionForExpansionState(expansion_state_); | |
| 146 gfx::Rect bounds = native_panel_->GetPanelBounds(); | |
| 147 bounds.set_y(bottom - height); | |
| 148 bounds.set_height(height); | |
| 149 SetPanelBounds(bounds); | |
| 150 | |
| 151 manager()->OnPanelExpansionStateChanged(old_state, new_state); | |
| 152 | 131 |
| 153 // The minimized panel should not get the focus. | 132 // The minimized panel should not get the focus. |
| 154 if (expansion_state_ == MINIMIZED) | 133 if (expansion_state_ == MINIMIZED) |
| 155 Deactivate(); | 134 Deactivate(); |
| 156 | 135 |
| 157 content::NotificationService::current()->Notify( | 136 content::NotificationService::current()->Notify( |
| 158 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, | 137 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, |
| 159 content::Source<Panel>(this), | 138 content::Source<Panel>(this), |
| 160 content::NotificationService::NoDetails()); | 139 content::NotificationService::NoDetails()); |
| 161 } | 140 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 182 | 161 |
| 183 bool Panel::IsDrawingAttention() const { | 162 bool Panel::IsDrawingAttention() const { |
| 184 return native_panel_->IsDrawingAttention(); | 163 return native_panel_->IsDrawingAttention(); |
| 185 } | 164 } |
| 186 | 165 |
| 187 void Panel::FullScreenModeChanged(bool is_full_screen) { | 166 void Panel::FullScreenModeChanged(bool is_full_screen) { |
| 188 native_panel_->FullScreenModeChanged(is_full_screen); | 167 native_panel_->FullScreenModeChanged(is_full_screen); |
| 189 } | 168 } |
| 190 | 169 |
| 191 void Panel::Show() { | 170 void Panel::Show() { |
| 192 native_panel_->ShowPanel(); | 171 // Don't show panel as active if it is in overflow state. |
| 172 if (expansion_state_ == IN_OVERFLOW) |
| 173 ShowInactive(); |
| 174 else |
| 175 native_panel_->ShowPanel(); |
| 193 } | 176 } |
| 194 | 177 |
| 195 void Panel::ShowInactive() { | 178 void Panel::ShowInactive() { |
| 196 native_panel_->ShowPanelInactive(); | 179 native_panel_->ShowPanelInactive(); |
| 197 } | 180 } |
| 198 | 181 |
| 199 void Panel::SetBounds(const gfx::Rect& bounds) { | 182 void Panel::SetBounds(const gfx::Rect& bounds) { |
| 200 // Ignore any SetBounds requests since the bounds are completely controlled | 183 // Ignore any SetBounds requests since the bounds are completely controlled |
| 201 // by panel manager. | 184 // by panel manager. |
| 202 } | 185 } |
| 203 | 186 |
| 204 // Close() may be called multiple times if the browser window is not ready to | 187 // Close() may be called multiple times if the browser window is not ready to |
| 205 // close on the first attempt. | 188 // close on the first attempt. |
| 206 void Panel::Close() { | 189 void Panel::Close() { |
| 207 native_panel_->ClosePanel(); | 190 native_panel_->ClosePanel(); |
| 208 } | 191 } |
| 209 | 192 |
| 193 void Panel::MoveOutOfOverflow() { |
| 194 if (expansion_state_ != Panel::IN_OVERFLOW) |
| 195 return; |
| 196 manager()->panel_overflow_strip()->Remove(this); |
| 197 manager()->panel_strip()->AddPanel(this); |
| 198 } |
| 199 |
| 210 void Panel::Activate() { | 200 void Panel::Activate() { |
| 201 MoveOutOfOverflow(); |
| 202 |
| 211 // Make sure the panel is expanded when activated programmatically, | 203 // Make sure the panel is expanded when activated programmatically, |
| 212 // so the user input does not go into collapsed window. | 204 // so the user input does not go into collapsed window. |
| 213 SetExpansionState(Panel::EXPANDED); | 205 SetExpansionState(Panel::EXPANDED); |
| 214 native_panel_->ActivatePanel(); | 206 native_panel_->ActivatePanel(); |
| 215 } | 207 } |
| 216 | 208 |
| 217 void Panel::Deactivate() { | 209 void Panel::Deactivate() { |
| 218 native_panel_->DeactivatePanel(); | 210 native_panel_->DeactivatePanel(); |
| 219 } | 211 } |
| 220 | 212 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 bounds.set_y(bounds.bottom() - restored_size_.height()); | 263 bounds.set_y(bounds.bottom() - restored_size_.height()); |
| 272 bounds.set_x(bounds.right() - restored_size_.width()); | 264 bounds.set_x(bounds.right() - restored_size_.width()); |
| 273 bounds.set_size(restored_size_); | 265 bounds.set_size(restored_size_); |
| 274 return bounds; | 266 return bounds; |
| 275 } | 267 } |
| 276 | 268 |
| 277 gfx::Rect Panel::GetBounds() const { | 269 gfx::Rect Panel::GetBounds() const { |
| 278 return native_panel_->GetPanelBounds(); | 270 return native_panel_->GetPanelBounds(); |
| 279 } | 271 } |
| 280 | 272 |
| 273 int Panel::TitleOnlyHeight() const { |
| 274 return native_panel_->TitleOnlyHeight(); |
| 275 } |
| 276 |
| 277 gfx::Size Panel::IconOnlySize() const { |
| 278 return native_panel_->IconOnlySize(); |
| 279 } |
| 280 |
| 281 void Panel::EnsureFullyVisible() { |
| 282 native_panel_->EnsurePanelFullyVisible(); |
| 283 } |
| 284 |
| 281 bool Panel::IsMaximized() const { | 285 bool Panel::IsMaximized() const { |
| 282 // Size of panels is managed by PanelManager, they are never 'zoomed'. | 286 // Size of panels is managed by PanelManager, they are never 'zoomed'. |
| 283 return false; | 287 return false; |
| 284 } | 288 } |
| 285 | 289 |
| 286 bool Panel::IsMinimized() const { | 290 bool Panel::IsMinimized() const { |
| 287 return expansion_state_ != EXPANDED; | 291 return expansion_state_ != EXPANDED; |
| 288 } | 292 } |
| 289 | 293 |
| 290 void Panel::Maximize() { | 294 void Panel::Maximize() { |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 native_panel_->ContentSizeFromWindowSize(max_size_)); | 633 native_panel_->ContentSizeFromWindowSize(max_size_)); |
| 630 } | 634 } |
| 631 | 635 |
| 632 void Panel::OnWindowSizeAvailable() { | 636 void Panel::OnWindowSizeAvailable() { |
| 633 ConfigureAutoResize(browser()->GetSelectedTabContents()); | 637 ConfigureAutoResize(browser()->GetSelectedTabContents()); |
| 634 } | 638 } |
| 635 | 639 |
| 636 void Panel::DestroyBrowser() { | 640 void Panel::DestroyBrowser() { |
| 637 native_panel_->DestroyPanelBrowser(); | 641 native_panel_->DestroyPanelBrowser(); |
| 638 } | 642 } |
| OLD | NEW |