Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: chrome/browser/ui/panels/panel_manager.cc

Issue 10051020: Move full-screen detection logic from PanelManager to DisplaySettingsProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix linux asan Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "chrome/browser/fullscreen.h"
14 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_list.h" 14 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/panels/detached_panel_strip.h" 15 #include "chrome/browser/ui/panels/detached_panel_strip.h"
17 #include "chrome/browser/ui/panels/docked_panel_strip.h" 16 #include "chrome/browser/ui/panels/docked_panel_strip.h"
18 #include "chrome/browser/ui/panels/overflow_panel_strip.h" 17 #include "chrome/browser/ui/panels/overflow_panel_strip.h"
19 #include "chrome/browser/ui/panels/panel_drag_controller.h" 18 #include "chrome/browser/ui/panels/panel_drag_controller.h"
20 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" 19 #include "chrome/browser/ui/panels/panel_mouse_watcher.h"
21 #include "chrome/browser/ui/panels/panel_resize_controller.h" 20 #include "chrome/browser/ui/panels/panel_resize_controller.h"
22 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/chrome_version_info.h" 23 #include "chrome/common/chrome_version_info.h"
25 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_source.h" 25 #include "content/public/browser/notification_source.h"
27 26
28 #if defined(TOOLKIT_GTK) 27 #if defined(TOOLKIT_GTK)
29 #include "ui/base/x/x11_util.h" 28 #include "ui/base/x/x11_util.h"
30 #endif 29 #endif
31 30
32 namespace { 31 namespace {
33 const int kOverflowStripThickness = 26; 32 const int kOverflowStripThickness = 26;
34 33
35 // Width of spacing around panel strip and the left/right edges of the screen. 34 // Width of spacing around panel strip and the left/right edges of the screen.
36 const int kPanelStripLeftMargin = kOverflowStripThickness + 6; 35 const int kPanelStripLeftMargin = kOverflowStripThickness + 6;
37 const int kPanelStripRightMargin = 24; 36 const int kPanelStripRightMargin = 24;
38 37
39 // Height of panel strip is based on the factor of the working area. 38 // Height of panel strip is based on the factor of the working area.
40 const double kPanelStripHeightFactor = 0.5; 39 const double kPanelStripHeightFactor = 0.5;
41 40
42 const int kFullScreenModeCheckIntervalMs = 1000;
43
44 // New panels that cannot fit in the panel strip are moved to overflow 41 // New panels that cannot fit in the panel strip are moved to overflow
45 // after a brief delay. 42 // after a brief delay.
46 const int kMoveNewPanelToOverflowDelayMs = 1500; // arbitrary 43 const int kMoveNewPanelToOverflowDelayMs = 1500; // arbitrary
47 } // namespace 44 } // namespace
48 45
49 // static 46 // static
50 bool PanelManager::shorten_time_intervals_ = false; 47 bool PanelManager::shorten_time_intervals_ = false;
51 48
52 // static 49 // static
53 PanelManager* PanelManager::GetInstance() { 50 PanelManager* PanelManager::GetInstance() {
(...skipping 25 matching lines...) Expand all
79 extension_id == std::string("ppleadejekpmccmnpjdimmlfljlkdfej") || 76 extension_id == std::string("ppleadejekpmccmnpjdimmlfljlkdfej") ||
80 extension_id == std::string("eggnbpckecmjlblplehfpjjdhhidfdoj"); 77 extension_id == std::string("eggnbpckecmjlblplehfpjjdhhidfdoj");
81 } 78 }
82 79
83 return true; 80 return true;
84 } 81 }
85 82
86 PanelManager::PanelManager() 83 PanelManager::PanelManager()
87 : panel_mouse_watcher_(PanelMouseWatcher::Create()), 84 : panel_mouse_watcher_(PanelMouseWatcher::Create()),
88 auto_sizing_enabled_(true), 85 auto_sizing_enabled_(true),
89 is_full_screen_(false),
90 is_processing_overflow_(false) { 86 is_processing_overflow_(false) {
91 // DisplaySettingsProvider should be created before the creation of strips 87 // DisplaySettingsProvider should be created before the creation of strips
92 // since some strip might depend on it. 88 // since some strip might depend on it.
93 display_settings_provider_.reset(DisplaySettingsProvider::Create()); 89 display_settings_provider_.reset(DisplaySettingsProvider::Create());
94 display_settings_provider_->set_display_area_observer(this); 90 display_settings_provider_->AddDisplayAreaObserver(this);
95 91
96 detached_strip_.reset(new DetachedPanelStrip(this)); 92 detached_strip_.reset(new DetachedPanelStrip(this));
97 docked_strip_.reset(new DockedPanelStrip(this)); 93 docked_strip_.reset(new DockedPanelStrip(this));
98 overflow_strip_.reset(new OverflowPanelStrip(this)); 94 overflow_strip_.reset(new OverflowPanelStrip(this));
99 drag_controller_.reset(new PanelDragController(this)); 95 drag_controller_.reset(new PanelDragController(this));
100 resize_controller_.reset(new PanelResizeController(this)); 96 resize_controller_.reset(new PanelResizeController(this));
101 } 97 }
102 98
103 PanelManager::~PanelManager() { 99 PanelManager::~PanelManager() {
100 display_settings_provider_->RemoveDisplayAreaObserver(this);
101
102 // Docked strip should be disposed explicitly before DisplaySettingsProvider
103 // is gone since docked strip needs to remove the observer from
104 // DisplaySettingsProvider.
105 docked_strip_.reset();
104 } 106 }
105 107
106 void PanelManager::OnDisplayAreaChanged(const gfx::Rect& display_area) { 108 void PanelManager::OnDisplayAreaChanged(const gfx::Rect& display_area) {
107 int height = 109 int height =
108 static_cast<int>(display_area.height() * kPanelStripHeightFactor); 110 static_cast<int>(display_area.height() * kPanelStripHeightFactor);
109 gfx::Rect docked_strip_bounds; 111 gfx::Rect docked_strip_bounds;
110 docked_strip_bounds.set_x(display_area.x() + kPanelStripLeftMargin); 112 docked_strip_bounds.set_x(display_area.x() + kPanelStripLeftMargin);
111 docked_strip_bounds.set_y(display_area.bottom() - height); 113 docked_strip_bounds.set_y(display_area.bottom() - height);
112 docked_strip_bounds.set_width(display_area.width() - 114 docked_strip_bounds.set_width(display_area.width() -
113 kPanelStripLeftMargin - kPanelStripRightMargin); 115 kPanelStripLeftMargin - kPanelStripRightMargin);
114 docked_strip_bounds.set_height(height); 116 docked_strip_bounds.set_height(height);
115 docked_strip_->SetDisplayArea(docked_strip_bounds); 117 docked_strip_->SetDisplayArea(docked_strip_bounds);
116 118
117 gfx::Rect overflow_area(display_area); 119 gfx::Rect overflow_area(display_area);
118 overflow_area.set_width(kOverflowStripThickness); 120 overflow_area.set_width(kOverflowStripThickness);
119 overflow_strip_->SetDisplayArea(overflow_area); 121 overflow_strip_->SetDisplayArea(overflow_area);
120 } 122 }
121 123
124 void PanelManager::OnFullScreenModeChanged(bool is_full_screen) {
125 docked_strip_->OnFullScreenModeChanged(is_full_screen);
126 overflow_strip_->OnFullScreenModeChanged(is_full_screen);
127 }
128
122 Panel* PanelManager::CreatePanel(Browser* browser) { 129 Panel* PanelManager::CreatePanel(Browser* browser) {
123 // Need to sync the display area if no panel is present. This is because: 130 // Need to sync the display area if no panel is present. This is because:
124 // 1) Display area is not initialized until first panel is created. 131 // 1) Display area is not initialized until first panel is created.
125 // 2) On windows, display settings notification is tied to a window. When 132 // 2) On windows, display settings notification is tied to a window. When
126 // display settings are changed at the time that no panel exists, we do 133 // display settings are changed at the time that no panel exists, we do
127 // not receive any notification. 134 // not receive any notification.
128 if (num_panels() == 0) 135 if (num_panels() == 0)
129 display_settings_provider_->OnDisplaySettingsChanged(); 136 display_settings_provider_->OnDisplaySettingsChanged();
130 137
131 int width = browser->override_bounds().width(); 138 int width = browser->override_bounds().width();
132 int height = browser->override_bounds().height(); 139 int height = browser->override_bounds().height();
133 Panel* panel = new Panel(browser, gfx::Size(width, height)); 140 Panel* panel = new Panel(browser, gfx::Size(width, height));
134 docked_strip_->AddPanel(panel, PanelStrip::DEFAULT_POSITION); 141 docked_strip_->AddPanel(panel, PanelStrip::DEFAULT_POSITION);
135 docked_strip_->UpdatePanelOnStripChange(panel); 142 docked_strip_->UpdatePanelOnStripChange(panel);
136 143
137 content::NotificationService::current()->Notify( 144 content::NotificationService::current()->Notify(
138 chrome::NOTIFICATION_PANEL_ADDED, 145 chrome::NOTIFICATION_PANEL_ADDED,
139 content::Source<Panel>(panel), 146 content::Source<Panel>(panel),
140 content::NotificationService::NoDetails()); 147 content::NotificationService::NoDetails());
141 148
142 if (num_panels() == 1) { 149 if (num_panels() == 1) {
143 full_screen_mode_timer_.Start(FROM_HERE, 150 display_settings_provider_->AddFullScreenObserver(this);
144 base::TimeDelta::FromMilliseconds(kFullScreenModeCheckIntervalMs),
145 this, &PanelManager::CheckFullScreenMode);
146 } 151 }
147 152
148 return panel; 153 return panel;
149 } 154 }
150 155
151 void PanelManager::CheckFullScreenMode() {
152 bool is_full_screen_new = IsFullScreenMode();
153 if (is_full_screen_ == is_full_screen_new)
154 return;
155 is_full_screen_ = is_full_screen_new;
156 docked_strip_->OnFullScreenModeChanged(is_full_screen_);
157 overflow_strip_->OnFullScreenModeChanged(is_full_screen_);
158 }
159
160 void PanelManager::OnPanelClosed(Panel* panel) { 156 void PanelManager::OnPanelClosed(Panel* panel) {
161 if (num_panels() == 1) 157 if (num_panels() == 1) {
162 full_screen_mode_timer_.Stop(); 158 display_settings_provider_->RemoveFullScreenObserver(this);
159 }
163 160
164 drag_controller_->OnPanelClosed(panel); 161 drag_controller_->OnPanelClosed(panel);
165 resize_controller_->OnPanelClosed(panel); 162 resize_controller_->OnPanelClosed(panel);
166 panel->panel_strip()->RemovePanel(panel); 163 panel->panel_strip()->RemovePanel(panel);
167 164
168 content::NotificationService::current()->Notify( 165 content::NotificationService::current()->Notify(
169 chrome::NOTIFICATION_PANEL_CLOSED, 166 chrome::NOTIFICATION_PANEL_CLOSED,
170 content::Source<Panel>(panel), 167 content::Source<Panel>(panel),
171 content::NotificationService::NoDetails()); 168 content::NotificationService::NoDetails());
172 } 169 }
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( 379 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval(
383 kMoveNewPanelToOverflowDelayMs))); 380 kMoveNewPanelToOverflowDelayMs)));
384 } 381 }
385 382
386 content::NotificationService::current()->Notify( 383 content::NotificationService::current()->Notify(
387 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, 384 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED,
388 content::Source<Panel>(panel), 385 content::Source<Panel>(panel),
389 content::NotificationService::NoDetails()); 386 content::NotificationService::NoDetails());
390 } 387 }
391 388
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_manager.h ('k') | chrome/browser/ui/panels/panel_window_controller_cocoa.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698