Chromium Code Reviews| 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 "content/browser/renderer_host/render_view_host.h" | |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/panels/native_panel.h" | 13 #include "chrome/browser/ui/panels/native_panel.h" |
| 13 #include "chrome/browser/ui/panels/panel_manager.h" | 14 #include "chrome/browser/ui/panels/panel_manager.h" |
| 14 #include "chrome/browser/ui/window_sizer.h" | 15 #include "chrome/browser/ui/window_sizer.h" |
| 15 #include "chrome/browser/web_applications/web_app.h" | 16 #include "chrome/browser/web_applications/web_app.h" |
| 16 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | |
| 19 #include "content/common/content_notification_types.h" | |
| 20 #include "content/common/view_messages.h" | |
| 17 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
| 18 | 22 |
| 19 // static | 23 // static |
| 20 const Extension* Panel::GetExtension(Browser* browser) { | 24 const Extension* Panel::GetExtension(Browser* browser) { |
| 21 // Find the extension. When we create a panel from an extension, the extension | 25 // Find the extension. When we create a panel from an extension, the extension |
| 22 // ID is passed as the app name to the Browser. | 26 // ID is passed as the app name to the Browser. |
| 23 ExtensionService* extension_service = | 27 ExtensionService* extension_service = |
| 24 browser->GetProfile()->GetExtensionService(); | 28 browser->GetProfile()->GetExtensionService(); |
| 25 return extension_service->GetExtensionById( | 29 return extension_service->GetExtensionById( |
| 26 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); | 30 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); |
| 27 } | 31 } |
| 28 | 32 |
| 29 Panel::Panel(Browser* browser, const gfx::Rect& bounds) | 33 Panel::Panel(Browser* browser, const gfx::Rect& bounds) |
| 30 : native_panel_(NULL), | 34 : initial_size_(bounds.size()), |
| 35 max_size_(bounds.size()), | |
| 36 native_panel_(NULL), | |
| 31 expansion_state_(EXPANDED) { | 37 expansion_state_(EXPANDED) { |
| 32 native_panel_ = CreateNativePanel(browser, this, bounds); | 38 native_panel_ = CreateNativePanel(browser, this, bounds); |
| 39 | |
| 40 registrar_.Add(this, | |
| 41 content::NOTIFICATION_TAB_ADDED, | |
| 42 Source<TabContentsDelegate>(browser)); | |
| 33 } | 43 } |
| 34 | 44 |
| 35 Panel::~Panel() { | 45 Panel::~Panel() { |
| 36 // Invoked by native panel so do not access native_panel_ here. | 46 // Invoked by native panel so do not access native_panel_ here. |
| 37 } | 47 } |
| 38 | 48 |
| 39 PanelManager* Panel::manager() const { | 49 PanelManager* Panel::manager() const { |
| 40 return PanelManager::GetInstance(); | 50 return PanelManager::GetInstance(); |
| 41 } | 51 } |
| 42 | 52 |
| 53 void Panel::SetRestoredBounds(const gfx::Rect& bounds) { | |
| 54 native_panel_->SetPanelRestoredBounds(bounds); | |
| 55 } | |
| 56 | |
| 43 void Panel::SetPanelBounds(const gfx::Rect& bounds) { | 57 void Panel::SetPanelBounds(const gfx::Rect& bounds) { |
| 44 native_panel_->SetPanelBounds(bounds); | 58 native_panel_->SetPanelBounds(bounds); |
| 45 } | 59 } |
| 46 | 60 |
| 61 void Panel::SetMaximumSize(const gfx::Size& max_size) { | |
| 62 if (max_size_ == max_size) | |
| 63 return; | |
| 64 max_size_ = max_size; | |
| 65 | |
| 66 // Tell the renderer not to show the scroll bar till |max_size_| since the | |
| 67 // panel can grow to |max_size_|. | |
| 68 // Note: It might be possible that the tab is not created yet. If so, we will | |
| 69 // send the message when NOTIFICATION_TAB_ADDED is received. | |
| 70 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
| 71 if (!tab_contents) | |
| 72 return; | |
| 73 RenderViewHost* render_view_host = tab_contents->render_view_host(); | |
| 74 if (!render_view_host) | |
| 75 return; | |
| 76 | |
| 77 gfx::Size non_client_size = GetNonClientAreaSize(); | |
| 78 render_view_host->Send(new ViewMsg_DisableScrollbarsForSmallWindows( | |
|
Dmitry Titov
2011/08/05 19:02:20
here you subtract non_client and in the notificati
jianli
2011/08/09 19:56:16
Done.
| |
| 79 render_view_host->routing_id(), | |
| 80 gfx::Size(max_size_.width() - non_client_size.width(), | |
| 81 max_size_.height() - non_client_size.height()))); | |
| 82 } | |
| 83 | |
| 47 void Panel::SetExpansionState(ExpansionState new_expansion_state) { | 84 void Panel::SetExpansionState(ExpansionState new_expansion_state) { |
| 48 if (expansion_state_ == new_expansion_state) | 85 if (expansion_state_ == new_expansion_state) |
| 49 return; | 86 return; |
| 50 | 87 |
| 51 expansion_state_ = new_expansion_state; | 88 expansion_state_ = new_expansion_state; |
| 52 | 89 |
| 53 native_panel_->OnPanelExpansionStateChanged(expansion_state_); | 90 native_panel_->OnPanelExpansionStateChanged(expansion_state_); |
| 54 | 91 |
| 55 // The minimized panel should not get the focus. | 92 // The minimized panel should not get the focus. |
| 56 if (expansion_state_ == MINIMIZED) | 93 if (expansion_state_ == MINIMIZED) |
| 57 Deactivate(); | 94 Deactivate(); |
| 58 } | 95 } |
| 59 | 96 |
| 60 bool Panel::ShouldBringUpTitleBar(int mouse_x, int mouse_y) const { | 97 bool Panel::ShouldBringUpTitleBar(int mouse_x, int mouse_y) const { |
| 61 // Skip the expanded panel. | 98 // Skip the expanded panel. |
| 62 if (expansion_state_ == Panel::EXPANDED) | 99 if (expansion_state_ == Panel::EXPANDED) |
| 63 return false; | 100 return false; |
| 64 | 101 |
| 65 // Let the native panel decide. | 102 // Let the native panel decide. |
| 66 return native_panel_->ShouldBringUpPanelTitleBar(mouse_x, mouse_y); | 103 return native_panel_->ShouldBringUpPanelTitleBar(mouse_x, mouse_y); |
| 67 } | 104 } |
| 68 | 105 |
| 69 bool Panel::IsDrawingAttention() const { | 106 bool Panel::IsDrawingAttention() const { |
| 70 return native_panel_->IsDrawingAttention(); | 107 return native_panel_->IsDrawingAttention(); |
| 71 } | 108 } |
| 72 | 109 |
| 110 gfx::Size Panel::GetNonClientAreaSize() const { | |
| 111 return native_panel_->GetNonClientAreaSize(); | |
| 112 } | |
| 113 | |
| 73 void Panel::Show() { | 114 void Panel::Show() { |
| 74 native_panel_->ShowPanel(); | 115 native_panel_->ShowPanel(); |
| 75 } | 116 } |
| 76 | 117 |
| 77 void Panel::ShowInactive() { | 118 void Panel::ShowInactive() { |
| 78 native_panel_->ShowPanelInactive(); | 119 native_panel_->ShowPanelInactive(); |
| 79 } | 120 } |
| 80 | 121 |
| 81 void Panel::SetBounds(const gfx::Rect& bounds) { | 122 void Panel::SetBounds(const gfx::Rect& bounds) { |
| 82 // Ignore any SetBounds requests since the bounds are completely controlled | 123 // Ignore any SetBounds requests since the bounds are completely controlled |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 | 180 |
| 140 void Panel::UpdateLoadingAnimations(bool should_animate) { | 181 void Panel::UpdateLoadingAnimations(bool should_animate) { |
| 141 NOTIMPLEMENTED(); | 182 NOTIMPLEMENTED(); |
| 142 } | 183 } |
| 143 | 184 |
| 144 void Panel::SetStarredState(bool is_starred) { | 185 void Panel::SetStarredState(bool is_starred) { |
| 145 NOTIMPLEMENTED(); | 186 NOTIMPLEMENTED(); |
| 146 } | 187 } |
| 147 | 188 |
| 148 gfx::Rect Panel::GetRestoredBounds() const { | 189 gfx::Rect Panel::GetRestoredBounds() const { |
| 149 return native_panel_->GetPanelBounds(); | 190 return native_panel_->GetPanelRestoredBounds(); |
| 150 } | 191 } |
| 151 | 192 |
| 152 gfx::Rect Panel::GetBounds() const { | 193 gfx::Rect Panel::GetBounds() const { |
| 153 return native_panel_->GetPanelBounds(); | 194 return native_panel_->GetPanelBounds(); |
| 154 } | 195 } |
| 155 | 196 |
| 156 bool Panel::IsMaximized() const { | 197 bool Panel::IsMaximized() const { |
| 157 NOTIMPLEMENTED(); | 198 NOTIMPLEMENTED(); |
| 158 return false; | 199 return false; |
| 159 } | 200 } |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 NOTIMPLEMENTED(); | 448 NOTIMPLEMENTED(); |
| 408 return NEW_POPUP; | 449 return NEW_POPUP; |
| 409 } | 450 } |
| 410 | 451 |
| 411 #if defined(OS_CHROMEOS) | 452 #if defined(OS_CHROMEOS) |
| 412 void Panel::ShowKeyboardOverlay(gfx::NativeWindow owning_window) { | 453 void Panel::ShowKeyboardOverlay(gfx::NativeWindow owning_window) { |
| 413 NOTIMPLEMENTED(); | 454 NOTIMPLEMENTED(); |
| 414 } | 455 } |
| 415 #endif | 456 #endif |
| 416 | 457 |
| 458 void Panel::UpdatePreferredSize(const gfx::Size& pref_size) { | |
| 459 return manager()->UpdatePreferredSize(this, pref_size); | |
|
Dmitry Titov
2011/08/05 19:02:20
As discussed, lets compute the window size here ri
jianli
2011/08/09 19:56:16
Done.
| |
| 460 } | |
| 461 | |
| 462 void Panel::Observe(int type, | |
| 463 const NotificationSource& source, | |
| 464 const NotificationDetails& details) { | |
| 465 switch (type) { | |
| 466 case content::NOTIFICATION_TAB_ADDED: { | |
| 467 RenderViewHost* render_view_host = | |
| 468 browser()->GetSelectedTabContents()->render_view_host(); | |
| 469 render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode( | |
| 470 render_view_host->routing_id(), | |
| 471 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow)); | |
| 472 render_view_host->Send(new ViewMsg_DisableScrollbarsForSmallWindows( | |
| 473 render_view_host->routing_id(), max_size_)); | |
| 474 } | |
| 475 default: | |
| 476 NOTREACHED() << "Got a notification we didn't register for!"; | |
| 477 break; | |
| 478 } | |
| 479 } | |
| 480 | |
| 417 Browser* Panel::browser() const { | 481 Browser* Panel::browser() const { |
| 418 return native_panel_->GetPanelBrowser(); | 482 return native_panel_->GetPanelBrowser(); |
| 419 } | 483 } |
| 420 | 484 |
| 421 void Panel::DestroyBrowser() { | 485 void Panel::DestroyBrowser() { |
| 422 native_panel_->DestroyPanelBrowser(); | 486 native_panel_->DestroyPanelBrowser(); |
| 423 } | 487 } |
| OLD | NEW |