| 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_->AddDisplayAreaObserver(this); |
| 90 | 85 |
| 91 detached_strip_.reset(new DetachedPanelStrip(this)); | 86 detached_strip_.reset(new DetachedPanelStrip(this)); |
| 92 docked_strip_.reset(new DockedPanelStrip(this)); | 87 docked_strip_.reset(new DockedPanelStrip(this)); |
| 93 overflow_strip_.reset(new OverflowPanelStrip(this)); | 88 overflow_strip_.reset(new OverflowPanelStrip(this)); |
| 94 drag_controller_.reset(new PanelDragController(this)); | 89 drag_controller_.reset(new PanelDragController(this)); |
| 95 resize_controller_.reset(new PanelResizeController(this)); | 90 resize_controller_.reset(new PanelResizeController(this)); |
| 96 } | 91 } |
| 97 | 92 |
| 98 PanelManager::~PanelManager() { | 93 PanelManager::~PanelManager() { |
| 94 display_settings_provider_->RemoveDisplayAreaObserver(this); |
| 99 } | 95 } |
| 100 | 96 |
| 101 void PanelManager::OnDisplayAreaChanged(const gfx::Rect& display_area) { | 97 void PanelManager::OnDisplayAreaChanged(const gfx::Rect& display_area) { |
| 102 int height = | 98 int height = |
| 103 static_cast<int>(display_area.height() * kPanelStripHeightFactor); | 99 static_cast<int>(display_area.height() * kPanelStripHeightFactor); |
| 104 gfx::Rect docked_strip_bounds; | 100 gfx::Rect docked_strip_bounds; |
| 105 docked_strip_bounds.set_x(display_area.x() + kPanelStripLeftMargin); | 101 docked_strip_bounds.set_x(display_area.x() + kPanelStripLeftMargin); |
| 106 docked_strip_bounds.set_y(display_area.bottom() - height); | 102 docked_strip_bounds.set_y(display_area.bottom() - height); |
| 107 docked_strip_bounds.set_width(display_area.width() - | 103 docked_strip_bounds.set_width(display_area.width() - |
| 108 kPanelStripLeftMargin - kPanelStripRightMargin); | 104 kPanelStripLeftMargin - kPanelStripRightMargin); |
| 109 docked_strip_bounds.set_height(height); | 105 docked_strip_bounds.set_height(height); |
| 110 docked_strip_->SetDisplayArea(docked_strip_bounds); | 106 docked_strip_->SetDisplayArea(docked_strip_bounds); |
| 111 | 107 |
| 112 gfx::Rect overflow_area(display_area); | 108 gfx::Rect overflow_area(display_area); |
| 113 overflow_area.set_width(kOverflowStripThickness); | 109 overflow_area.set_width(kOverflowStripThickness); |
| 114 overflow_strip_->SetDisplayArea(overflow_area); | 110 overflow_strip_->SetDisplayArea(overflow_area); |
| 115 } | 111 } |
| 116 | 112 |
| 113 void PanelManager::OnFullScreenModeChanged(bool is_full_screen) { |
| 114 docked_strip_->OnFullScreenModeChanged(is_full_screen); |
| 115 overflow_strip_->OnFullScreenModeChanged(is_full_screen); |
| 116 } |
| 117 |
| 117 Panel* PanelManager::CreatePanel(Browser* browser) { | 118 Panel* PanelManager::CreatePanel(Browser* browser) { |
| 118 // Need to sync the display area if no panel is present. This is because: | 119 // 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. | 120 // 1) Display area is not initialized until first panel is created. |
| 120 // 2) On windows, display settings notification is tied to a window. When | 121 // 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 | 122 // display settings are changed at the time that no panel exists, we do |
| 122 // not receive any notification. | 123 // not receive any notification. |
| 123 if (num_panels() == 0) | 124 if (num_panels() == 0) |
| 124 display_settings_provider_->OnDisplaySettingsChanged(); | 125 display_settings_provider_->OnDisplaySettingsChanged(); |
| 125 | 126 |
| 126 int width = browser->override_bounds().width(); | 127 int width = browser->override_bounds().width(); |
| 127 int height = browser->override_bounds().height(); | 128 int height = browser->override_bounds().height(); |
| 128 Panel* panel = new Panel(browser, gfx::Size(width, height)); | 129 Panel* panel = new Panel(browser, gfx::Size(width, height)); |
| 129 docked_strip_->AddPanel(panel, PanelStrip::DEFAULT_POSITION); | 130 docked_strip_->AddPanel(panel, PanelStrip::DEFAULT_POSITION); |
| 130 docked_strip_->UpdatePanelOnStripChange(panel); | 131 docked_strip_->UpdatePanelOnStripChange(panel); |
| 131 | 132 |
| 132 content::NotificationService::current()->Notify( | 133 content::NotificationService::current()->Notify( |
| 133 chrome::NOTIFICATION_PANEL_ADDED, | 134 chrome::NOTIFICATION_PANEL_ADDED, |
| 134 content::Source<Panel>(panel), | 135 content::Source<Panel>(panel), |
| 135 content::NotificationService::NoDetails()); | 136 content::NotificationService::NoDetails()); |
| 136 | 137 |
| 137 if (num_panels() == 1) { | 138 if (num_panels() == 1) { |
| 138 full_screen_mode_timer_.Start(FROM_HERE, | 139 display_settings_provider_->AddFullScreenObserver(this); |
| 139 base::TimeDelta::FromMilliseconds(kFullScreenModeCheckIntervalMs), | |
| 140 this, &PanelManager::CheckFullScreenMode); | |
| 141 } | 140 } |
| 142 | 141 |
| 143 return panel; | 142 return panel; |
| 144 } | 143 } |
| 145 | 144 |
| 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) { | 145 void PanelManager::OnPanelClosed(Panel* panel) { |
| 156 if (num_panels() == 1) | 146 if (num_panels() == 1) { |
| 157 full_screen_mode_timer_.Stop(); | 147 display_settings_provider_->RemoveFullScreenObserver(this); |
| 148 } |
| 158 | 149 |
| 159 drag_controller_->OnPanelClosed(panel); | 150 drag_controller_->OnPanelClosed(panel); |
| 160 resize_controller_->OnPanelClosed(panel); | 151 resize_controller_->OnPanelClosed(panel); |
| 161 panel->panel_strip()->RemovePanel(panel); | 152 panel->panel_strip()->RemovePanel(panel); |
| 162 | 153 |
| 163 content::NotificationService::current()->Notify( | 154 content::NotificationService::current()->Notify( |
| 164 chrome::NOTIFICATION_PANEL_CLOSED, | 155 chrome::NOTIFICATION_PANEL_CLOSED, |
| 165 content::Source<Panel>(panel), | 156 content::Source<Panel>(panel), |
| 166 content::NotificationService::NoDetails()); | 157 content::NotificationService::NoDetails()); |
| 167 } | 158 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 return panels; | 340 return panels; |
| 350 } | 341 } |
| 351 | 342 |
| 352 int PanelManager::overflow_strip_width() const { | 343 int PanelManager::overflow_strip_width() const { |
| 353 return kOverflowStripThickness; | 344 return kOverflowStripThickness; |
| 354 } | 345 } |
| 355 | 346 |
| 356 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { | 347 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { |
| 357 panel_mouse_watcher_.reset(watcher); | 348 panel_mouse_watcher_.reset(watcher); |
| 358 } | 349 } |
| OLD | NEW |