Chromium Code Reviews| 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_manager.h" | 5 #include "chrome/browser/ui/panels/panel_manager.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/fullscreen.h" | |
| 12 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
| 14 #include "chrome/browser/ui/panels/detached_panel_strip.h" | 13 #include "chrome/browser/ui/panels/detached_panel_strip.h" |
| 15 #include "chrome/browser/ui/panels/docked_panel_strip.h" | 14 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
| 16 #include "chrome/browser/ui/panels/overflow_panel_strip.h" | 15 #include "chrome/browser/ui/panels/overflow_panel_strip.h" |
| 17 #include "chrome/browser/ui/panels/panel_drag_controller.h" | 16 #include "chrome/browser/ui/panels/panel_drag_controller.h" |
| 18 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 17 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
| 19 #include "chrome/browser/ui/panels/panel_resize_controller.h" | 18 #include "chrome/browser/ui/panels/panel_resize_controller.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/chrome_version_info.h" | 21 #include "chrome/common/chrome_version_info.h" |
| 23 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 25 | 24 |
| 26 #if defined(TOOLKIT_GTK) | 25 #if defined(TOOLKIT_GTK) |
| 27 #include "ui/base/x/x11_util.h" | 26 #include "ui/base/x/x11_util.h" |
| 28 #endif | 27 #endif |
| 29 | 28 |
| 30 namespace { | 29 namespace { |
| 31 const int kOverflowStripThickness = 26; | 30 const int kOverflowStripThickness = 26; |
| 32 | 31 |
| 33 // Width of spacing around panel strip and the left/right edges of the screen. | 32 // Width of spacing around panel strip and the left/right edges of the screen. |
| 34 const int kPanelStripLeftMargin = kOverflowStripThickness + 6; | 33 const int kPanelStripLeftMargin = kOverflowStripThickness + 6; |
| 35 const int kPanelStripRightMargin = 24; | 34 const int kPanelStripRightMargin = 24; |
| 36 | 35 |
| 37 // Height of panel strip is based on the factor of the working area. | 36 // Height of panel strip is based on the factor of the working area. |
| 38 const double kPanelStripHeightFactor = 0.5; | 37 const double kPanelStripHeightFactor = 0.5; |
| 39 | |
| 40 static const int kFullScreenModeCheckIntervalMs = 1000; | |
| 41 | |
| 42 } // namespace | 38 } // namespace |
| 43 | 39 |
| 44 // static | 40 // static |
| 45 bool PanelManager::shorten_time_intervals_ = false; | 41 bool PanelManager::shorten_time_intervals_ = false; |
| 46 | 42 |
| 47 // static | 43 // static |
| 48 PanelManager* PanelManager::GetInstance() { | 44 PanelManager* PanelManager::GetInstance() { |
| 49 static base::LazyInstance<PanelManager> instance = LAZY_INSTANCE_INITIALIZER; | 45 static base::LazyInstance<PanelManager> instance = LAZY_INSTANCE_INITIALIZER; |
| 50 return instance.Pointer(); | 46 return instance.Pointer(); |
| 51 } | 47 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 74 extension_id == std::string("ppleadejekpmccmnpjdimmlfljlkdfej") || | 70 extension_id == std::string("ppleadejekpmccmnpjdimmlfljlkdfej") || |
| 75 extension_id == std::string("eggnbpckecmjlblplehfpjjdhhidfdoj"); | 71 extension_id == std::string("eggnbpckecmjlblplehfpjjdhhidfdoj"); |
| 76 } | 72 } |
| 77 | 73 |
| 78 return true; | 74 return true; |
| 79 } | 75 } |
| 80 | 76 |
| 81 PanelManager::PanelManager() | 77 PanelManager::PanelManager() |
| 82 : panel_mouse_watcher_(PanelMouseWatcher::Create()), | 78 : panel_mouse_watcher_(PanelMouseWatcher::Create()), |
| 83 auto_sizing_enabled_(true), | 79 auto_sizing_enabled_(true), |
| 84 is_full_screen_(false), | |
| 85 is_processing_overflow_(false) { | 80 is_processing_overflow_(false) { |
| 86 // DisplaySettingsProvider should be created before the creation of strips | 81 // DisplaySettingsProvider should be created before the creation of strips |
| 87 // since some strip might depend on it. | 82 // since some strip might depend on it. |
| 88 display_settings_provider_.reset(DisplaySettingsProvider::Create()); | 83 display_settings_provider_.reset(DisplaySettingsProvider::Create()); |
| 89 display_settings_provider_->set_display_area_observer(this); | 84 display_settings_provider_->AddObserver( |
| 85 static_cast<DisplaySettingsProvider::DisplayAreaObserver*>(this)); | |
| 90 | 86 |
| 91 detached_strip_.reset(new DetachedPanelStrip(this)); | 87 detached_strip_.reset(new DetachedPanelStrip(this)); |
| 92 docked_strip_.reset(new DockedPanelStrip(this)); | 88 docked_strip_.reset(new DockedPanelStrip(this)); |
| 93 overflow_strip_.reset(new OverflowPanelStrip(this)); | 89 overflow_strip_.reset(new OverflowPanelStrip(this)); |
| 94 drag_controller_.reset(new PanelDragController(this)); | 90 drag_controller_.reset(new PanelDragController(this)); |
| 95 resize_controller_.reset(new PanelResizeController(this)); | 91 resize_controller_.reset(new PanelResizeController(this)); |
| 96 } | 92 } |
| 97 | 93 |
| 98 PanelManager::~PanelManager() { | 94 PanelManager::~PanelManager() { |
| 95 display_settings_provider_->RemoveObserver( | |
| 96 static_cast<DisplaySettingsProvider::DisplayAreaObserver*>(this)); | |
| 99 } | 97 } |
| 100 | 98 |
| 101 void PanelManager::OnDisplayAreaChanged(const gfx::Rect& display_area) { | 99 void PanelManager::OnDisplayAreaChanged(const gfx::Rect& display_area) { |
| 102 int height = | 100 int height = |
| 103 static_cast<int>(display_area.height() * kPanelStripHeightFactor); | 101 static_cast<int>(display_area.height() * kPanelStripHeightFactor); |
| 104 gfx::Rect docked_strip_bounds; | 102 gfx::Rect docked_strip_bounds; |
| 105 docked_strip_bounds.set_x(display_area.x() + kPanelStripLeftMargin); | 103 docked_strip_bounds.set_x(display_area.x() + kPanelStripLeftMargin); |
| 106 docked_strip_bounds.set_y(display_area.bottom() - height); | 104 docked_strip_bounds.set_y(display_area.bottom() - height); |
| 107 docked_strip_bounds.set_width(display_area.width() - | 105 docked_strip_bounds.set_width(display_area.width() - |
| 108 kPanelStripLeftMargin - kPanelStripRightMargin); | 106 kPanelStripLeftMargin - kPanelStripRightMargin); |
| 109 docked_strip_bounds.set_height(height); | 107 docked_strip_bounds.set_height(height); |
| 110 docked_strip_->SetDisplayArea(docked_strip_bounds); | 108 docked_strip_->SetDisplayArea(docked_strip_bounds); |
| 111 | 109 |
| 112 gfx::Rect overflow_area(display_area); | 110 gfx::Rect overflow_area(display_area); |
| 113 overflow_area.set_width(kOverflowStripThickness); | 111 overflow_area.set_width(kOverflowStripThickness); |
| 114 overflow_strip_->SetDisplayArea(overflow_area); | 112 overflow_strip_->SetDisplayArea(overflow_area); |
| 115 } | 113 } |
| 116 | 114 |
| 115 void PanelManager::OnFullScreenModeChanged(bool is_full_screen) { | |
| 116 docked_strip_->OnFullScreenModeChanged(is_full_screen); | |
| 117 overflow_strip_->OnFullScreenModeChanged(is_full_screen); | |
| 118 } | |
| 119 | |
| 117 Panel* PanelManager::CreatePanel(Browser* browser) { | 120 Panel* PanelManager::CreatePanel(Browser* browser) { |
| 118 // Need to sync the display area if no panel is present. This is because: | 121 // Need to sync the display area if no panel is present. This is because: |
| 119 // 1) Display area is not initialized until first panel is created. | 122 // 1) Display area is not initialized until first panel is created. |
| 120 // 2) On windows, display settings notification is tied to a window. When | 123 // 2) On windows, display settings notification is tied to a window. When |
| 121 // display settings are changed at the time that no panel exists, we do | 124 // display settings are changed at the time that no panel exists, we do |
| 122 // not receive any notification. | 125 // not receive any notification. |
| 123 if (num_panels() == 0) | 126 if (num_panels() == 0) |
| 124 display_settings_provider_->OnDisplaySettingsChanged(); | 127 display_settings_provider_->OnDisplaySettingsChanged(); |
| 125 | 128 |
| 126 int width = browser->override_bounds().width(); | 129 int width = browser->override_bounds().width(); |
| 127 int height = browser->override_bounds().height(); | 130 int height = browser->override_bounds().height(); |
| 128 Panel* panel = new Panel(browser, gfx::Size(width, height)); | 131 Panel* panel = new Panel(browser, gfx::Size(width, height)); |
| 129 docked_strip_->AddPanel(panel, PanelStrip::DEFAULT_POSITION); | 132 docked_strip_->AddPanel(panel, PanelStrip::DEFAULT_POSITION); |
| 130 docked_strip_->UpdatePanelOnStripChange(panel); | 133 docked_strip_->UpdatePanelOnStripChange(panel); |
| 131 | 134 |
| 132 content::NotificationService::current()->Notify( | 135 content::NotificationService::current()->Notify( |
| 133 chrome::NOTIFICATION_PANEL_ADDED, | 136 chrome::NOTIFICATION_PANEL_ADDED, |
| 134 content::Source<Panel>(panel), | 137 content::Source<Panel>(panel), |
| 135 content::NotificationService::NoDetails()); | 138 content::NotificationService::NoDetails()); |
| 136 | 139 |
| 137 if (num_panels() == 1) { | 140 if (num_panels() == 1) { |
| 138 full_screen_mode_timer_.Start(FROM_HERE, | 141 display_settings_provider_->AddObserver( |
| 139 base::TimeDelta::FromMilliseconds(kFullScreenModeCheckIntervalMs), | 142 static_cast<DisplaySettingsProvider::FullScreenObserver*>(this)); |
|
Dmitry Titov
2012/04/12 00:08:51
These casts will also go away if observers are not
jianli
2012/04/12 00:45:17
Done.
| |
| 140 this, &PanelManager::CheckFullScreenMode); | |
| 141 } | 143 } |
| 142 | 144 |
| 143 return panel; | 145 return panel; |
| 144 } | 146 } |
| 145 | 147 |
| 146 void PanelManager::CheckFullScreenMode() { | |
| 147 bool is_full_screen_new = IsFullScreenMode(); | |
| 148 if (is_full_screen_ == is_full_screen_new) | |
| 149 return; | |
| 150 is_full_screen_ = is_full_screen_new; | |
| 151 docked_strip_->OnFullScreenModeChanged(is_full_screen_); | |
| 152 overflow_strip_->OnFullScreenModeChanged(is_full_screen_); | |
| 153 } | |
| 154 | |
| 155 void PanelManager::OnPanelClosed(Panel* panel) { | 148 void PanelManager::OnPanelClosed(Panel* panel) { |
| 156 if (num_panels() == 1) | 149 if (num_panels() == 1) { |
| 157 full_screen_mode_timer_.Stop(); | 150 display_settings_provider_->RemoveObserver( |
| 151 static_cast<DisplaySettingsProvider::FullScreenObserver*>(this)); | |
| 152 } | |
| 158 | 153 |
| 159 drag_controller_->OnPanelClosed(panel); | 154 drag_controller_->OnPanelClosed(panel); |
| 160 resize_controller_->OnPanelClosed(panel); | 155 resize_controller_->OnPanelClosed(panel); |
| 161 panel->panel_strip()->RemovePanel(panel); | 156 panel->panel_strip()->RemovePanel(panel); |
| 162 | 157 |
| 163 content::NotificationService::current()->Notify( | 158 content::NotificationService::current()->Notify( |
| 164 chrome::NOTIFICATION_PANEL_CLOSED, | 159 chrome::NOTIFICATION_PANEL_CLOSED, |
| 165 content::Source<Panel>(panel), | 160 content::Source<Panel>(panel), |
| 166 content::NotificationService::NoDetails()); | 161 content::NotificationService::NoDetails()); |
| 167 } | 162 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 return panels; | 344 return panels; |
| 350 } | 345 } |
| 351 | 346 |
| 352 int PanelManager::overflow_strip_width() const { | 347 int PanelManager::overflow_strip_width() const { |
| 353 return kOverflowStripThickness; | 348 return kOverflowStripThickness; |
| 354 } | 349 } |
| 355 | 350 |
| 356 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { | 351 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { |
| 357 panel_mouse_watcher_.reset(watcher); | 352 panel_mouse_watcher_.reset(watcher); |
| 358 } | 353 } |
| OLD | NEW |