| 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" |
| 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 if (old_state == IN_OVERFLOW && new_state != IN_OVERFLOW) |
| 131 switch (expansion_state_) { | 132 manager()->panel_overflow_strip()->Remove(this); |
| 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 | 133 |
| 147 int bottom = manager()->GetBottomPositionForExpansionState(expansion_state_); | 134 manager()->OnPanelExpansionStateChanged(this, old_state); |
| 148 gfx::Rect bounds = native_panel_->GetPanelBounds(); | |
| 149 bounds.set_y(bottom - height); | |
| 150 bounds.set_height(height); | |
| 151 SetPanelBounds(bounds); | |
| 152 | 135 |
| 153 manager()->OnPanelExpansionStateChanged(old_state, new_state); | 136 if (old_state == IN_OVERFLOW && new_state != IN_OVERFLOW) |
| 137 manager()->panel_strip()->AddPanel(this); |
| 154 | 138 |
| 155 // The minimized panel should not get the focus. | 139 // The minimized panel should not get the focus. |
| 156 if (expansion_state_ == MINIMIZED) | 140 if (expansion_state_ == MINIMIZED) |
| 157 Deactivate(); | 141 Deactivate(); |
| 158 | 142 |
| 159 content::NotificationService::current()->Notify( | 143 content::NotificationService::current()->Notify( |
| 160 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, | 144 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, |
| 161 content::Source<Panel>(this), | 145 content::Source<Panel>(this), |
| 162 content::NotificationService::NoDetails()); | 146 content::NotificationService::NoDetails()); |
| 163 } | 147 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 180 gfx::Rect bounds = native_panel_->GetPanelBounds(); | 164 gfx::Rect bounds = native_panel_->GetPanelBounds(); |
| 181 return bounds.x() <= mouse_x && mouse_x <= bounds.right() && | 165 return bounds.x() <= mouse_x && mouse_x <= bounds.right() && |
| 182 mouse_y >= bounds.y(); | 166 mouse_y >= bounds.y(); |
| 183 } | 167 } |
| 184 | 168 |
| 185 bool Panel::IsDrawingAttention() const { | 169 bool Panel::IsDrawingAttention() const { |
| 186 return native_panel_->IsDrawingAttention(); | 170 return native_panel_->IsDrawingAttention(); |
| 187 } | 171 } |
| 188 | 172 |
| 189 void Panel::Show() { | 173 void Panel::Show() { |
| 190 native_panel_->ShowPanel(); | 174 // Don't show panel as active if it is in overflow state. |
| 175 if (expansion_state_ == IN_OVERFLOW) |
| 176 native_panel_->ShowPanelInactive(); |
| 177 else |
| 178 native_panel_->ShowPanel(); |
| 191 } | 179 } |
| 192 | 180 |
| 193 void Panel::ShowInactive() { | 181 void Panel::ShowInactive() { |
| 194 native_panel_->ShowPanelInactive(); | 182 native_panel_->ShowPanelInactive(); |
| 195 } | 183 } |
| 196 | 184 |
| 197 void Panel::SetBounds(const gfx::Rect& bounds) { | 185 void Panel::SetBounds(const gfx::Rect& bounds) { |
| 198 // Ignore any SetBounds requests since the bounds are completely controlled | 186 // Ignore any SetBounds requests since the bounds are completely controlled |
| 199 // by panel manager. | 187 // by panel manager. |
| 200 } | 188 } |
| 201 | 189 |
| 202 // Close() may be called multiple times if the browser window is not ready to | 190 // Close() may be called multiple times if the browser window is not ready to |
| 203 // close on the first attempt. | 191 // close on the first attempt. |
| 204 void Panel::Close() { | 192 void Panel::Close() { |
| 205 native_panel_->ClosePanel(); | 193 native_panel_->ClosePanel(); |
| 206 } | 194 } |
| 207 | 195 |
| 208 void Panel::Activate() { | 196 void Panel::Activate() { |
| 197 // Don't activate the panel if it is in overflow state. |
| 198 if (expansion_state_ == IN_OVERFLOW) |
| 199 return; |
| 200 |
| 209 // Make sure the panel is expanded when activated programmatically, | 201 // Make sure the panel is expanded when activated programmatically, |
| 210 // so the user input does not go into collapsed window. | 202 // so the user input does not go into collapsed window. |
| 211 SetExpansionState(Panel::EXPANDED); | 203 SetExpansionState(Panel::EXPANDED); |
| 212 native_panel_->ActivatePanel(); | 204 native_panel_->ActivatePanel(); |
| 213 } | 205 } |
| 214 | 206 |
| 215 void Panel::Deactivate() { | 207 void Panel::Deactivate() { |
| 216 native_panel_->DeactivatePanel(); | 208 native_panel_->DeactivatePanel(); |
| 217 } | 209 } |
| 218 | 210 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 bounds.set_y(bounds.bottom() - restored_size_.height()); | 261 bounds.set_y(bounds.bottom() - restored_size_.height()); |
| 270 bounds.set_x(bounds.right() - restored_size_.width()); | 262 bounds.set_x(bounds.right() - restored_size_.width()); |
| 271 bounds.set_size(restored_size_); | 263 bounds.set_size(restored_size_); |
| 272 return bounds; | 264 return bounds; |
| 273 } | 265 } |
| 274 | 266 |
| 275 gfx::Rect Panel::GetBounds() const { | 267 gfx::Rect Panel::GetBounds() const { |
| 276 return native_panel_->GetPanelBounds(); | 268 return native_panel_->GetPanelBounds(); |
| 277 } | 269 } |
| 278 | 270 |
| 271 int Panel::TitleOnlyHeight() const { |
| 272 return native_panel_->TitleOnlyHeight(); |
| 273 } |
| 274 |
| 275 gfx::Size Panel::IconOnlySize() const { |
| 276 return native_panel_->IconOnlySize(); |
| 277 } |
| 278 |
| 279 void Panel::EnsureFullyVisible() { |
| 280 native_panel_->EnsurePanelFullyVisible(); |
| 281 } |
| 282 |
| 279 bool Panel::IsMaximized() const { | 283 bool Panel::IsMaximized() const { |
| 280 // Size of panels is managed by PanelManager, they are never 'zoomed'. | 284 // Size of panels is managed by PanelManager, they are never 'zoomed'. |
| 281 return false; | 285 return false; |
| 282 } | 286 } |
| 283 | 287 |
| 284 bool Panel::IsMinimized() const { | 288 bool Panel::IsMinimized() const { |
| 285 return expansion_state_ != EXPANDED; | 289 return expansion_state_ != EXPANDED; |
| 286 } | 290 } |
| 287 | 291 |
| 288 void Panel::Maximize() { | 292 void Panel::Maximize() { |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 if (auto_resizable_) { | 651 if (auto_resizable_) { |
| 648 RenderViewHost* render_view_host = GetRenderViewHost(); | 652 RenderViewHost* render_view_host = GetRenderViewHost(); |
| 649 if (render_view_host) | 653 if (render_view_host) |
| 650 RequestRenderViewHostToDisableScrollbars(render_view_host); | 654 RequestRenderViewHostToDisableScrollbars(render_view_host); |
| 651 } | 655 } |
| 652 } | 656 } |
| 653 | 657 |
| 654 void Panel::DestroyBrowser() { | 658 void Panel::DestroyBrowser() { |
| 655 native_panel_->DestroyPanelBrowser(); | 659 native_panel_->DestroyPanelBrowser(); |
| 656 } | 660 } |
| OLD | NEW |