| 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_manager.h" | 5 #include "chrome/browser/ui/panels/panel_strip.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 13 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/panels/panel_manager.h" |
| 15 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 14 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
| 16 #include "chrome/browser/ui/window_sizer.h" | |
| 17 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
| 20 | 18 |
| 21 namespace { | 19 namespace { |
| 22 // Invalid panel index. | 20 // Invalid panel index. |
| 23 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); | 21 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); |
| 24 | 22 |
| 25 // Width of spacing between first panel and the right edge of the screen. | |
| 26 // Leaving a larger gap at the edge of the screen allows access to UI | |
| 27 // elements located on the bottom right of windows. | |
| 28 const int kRightScreenEdgeSpacingWidth = 24; | |
| 29 | |
| 30 // Width to height ratio is used to compute the default width or height | 23 // Width to height ratio is used to compute the default width or height |
| 31 // when only one value is provided. | 24 // when only one value is provided. |
| 32 const double kPanelDefaultWidthToHeightRatio = 1.62; // golden ratio | 25 const double kPanelDefaultWidthToHeightRatio = 1.62; // golden ratio |
| 33 | 26 |
| 34 // Maxmium width and height of a panel based on the factor of the working | 27 // Maxmium width of a panel is based on a factor of the entire panel strip. |
| 35 // area. | |
| 36 const double kPanelMaxWidthFactor = 0.35; | 28 const double kPanelMaxWidthFactor = 0.35; |
| 37 const double kPanelMaxHeightFactor = 0.5; | |
| 38 | 29 |
| 39 // Occasionally some system, like Windows, might not bring up or down the bottom | 30 // Occasionally some system, like Windows, might not bring up or down the bottom |
| 40 // bar when the mouse enters or leaves the bottom screen area. This is the | 31 // bar when the mouse enters or leaves the bottom screen area. This is the |
| 41 // maximum time we will wait for the bottom bar visibility change notification. | 32 // maximum time we will wait for the bottom bar visibility change notification. |
| 42 // After the time expires, we bring up/down the titlebars as planned. | 33 // After the time expires, we bring up/down the titlebars as planned. |
| 43 const int kMaxMillisecondsWaitForBottomBarVisibilityChange = 1000; | 34 const int kMaxMillisecondsWaitForBottomBarVisibilityChange = 1000; |
| 44 | 35 |
| 45 // See usage below. | 36 // See usage below. |
| 46 #if defined(TOOLKIT_GTK) | 37 #if defined(TOOLKIT_GTK) |
| 47 const int kMillisecondsBeforeCollapsingFromTitleOnlyState = 2000; | 38 const int kMillisecondsBeforeCollapsingFromTitleOnlyState = 2000; |
| 48 #else | 39 #else |
| 49 const int kMillisecondsBeforeCollapsingFromTitleOnlyState = 0; | 40 const int kMillisecondsBeforeCollapsingFromTitleOnlyState = 0; |
| 50 #endif | 41 #endif |
| 51 } // namespace | 42 } // namespace |
| 52 | 43 |
| 53 // static | 44 // static |
| 54 const int PanelManager::kPanelMinWidth = 100; | 45 const int PanelStrip::kPanelMinWidth = 100; |
| 55 const int PanelManager::kPanelMinHeight = 20; | 46 const int PanelStrip::kPanelMinHeight = 20; |
| 56 | 47 |
| 57 // static | 48 PanelStrip::PanelStrip(PanelManager* panel_manager) |
| 58 PanelManager* PanelManager::GetInstance() { | 49 : panel_manager_(panel_manager), |
| 59 static base::LazyInstance<PanelManager> instance = LAZY_INSTANCE_INITIALIZER; | 50 minimized_panel_count_(0), |
| 60 return instance.Pointer(); | |
| 61 } | |
| 62 | |
| 63 PanelManager::PanelManager() | |
| 64 : minimized_panel_count_(0), | |
| 65 are_titlebars_up_(false), | 51 are_titlebars_up_(false), |
| 66 dragging_panel_index_(kInvalidPanelIndex), | 52 dragging_panel_index_(kInvalidPanelIndex), |
| 67 dragging_panel_original_x_(0), | 53 dragging_panel_original_x_(0), |
| 68 delayed_titlebar_action_(NO_ACTION), | 54 delayed_titlebar_action_(NO_ACTION), |
| 69 remove_delays_for_testing_(false), | 55 remove_delays_for_testing_(false), |
| 70 titlebar_action_factory_(this), | 56 titlebar_action_factory_(this) { |
| 71 auto_sizing_enabled_(true), | |
| 72 mouse_watching_disabled_(false) { | |
| 73 panel_mouse_watcher_.reset(PanelMouseWatcher::Create()); | |
| 74 auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); | |
| 75 OnDisplayChanged(); | |
| 76 } | 57 } |
| 77 | 58 |
| 78 PanelManager::~PanelManager() { | 59 PanelStrip::~PanelStrip() { |
| 79 DCHECK(panels_.empty()); | 60 DCHECK(panels_.empty()); |
| 80 DCHECK(panels_pending_to_remove_.empty()); | 61 DCHECK(panels_pending_to_remove_.empty()); |
| 81 DCHECK_EQ(0, minimized_panel_count_); | 62 DCHECK_EQ(0, minimized_panel_count_); |
| 82 } | 63 } |
| 83 | 64 |
| 84 void PanelManager::OnDisplayChanged() { | 65 void PanelStrip::SetBounds(const gfx::Rect bounds) { |
| 85 scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider( | 66 if (strip_bounds_ == bounds) |
| 86 WindowSizer::CreateDefaultMonitorInfoProvider()); | 67 return; |
| 87 #if defined(OS_MACOSX) | |
| 88 // On OSX, panels should be dropped all the way to the bottom edge of the | |
| 89 // screen (and overlap Dock). | |
| 90 gfx::Rect work_area = info_provider->GetPrimaryMonitorBounds(); | |
| 91 #else | |
| 92 gfx::Rect work_area = info_provider->GetPrimaryMonitorWorkArea(); | |
| 93 #endif | |
| 94 SetWorkArea(work_area); | |
| 95 } | |
| 96 | 68 |
| 97 void PanelManager::SetWorkArea(const gfx::Rect& work_area) { | 69 strip_bounds_ = bounds; |
| 98 if (work_area == work_area_) | |
| 99 return; | |
| 100 work_area_ = work_area; | |
| 101 | |
| 102 auto_hiding_desktop_bar_->UpdateWorkArea(work_area_); | |
| 103 AdjustWorkAreaForAutoHidingDesktopBars(); | |
| 104 | |
| 105 Rearrange(panels_.begin(), StartingRightPosition()); | 70 Rearrange(panels_.begin(), StartingRightPosition()); |
| 106 } | 71 } |
| 107 | 72 |
| 108 Panel* PanelManager::CreatePanel(Browser* browser) { | 73 void PanelStrip::AddPanel(Panel* panel) { |
| 109 int width = browser->override_bounds().width(); | 74 if (panel->initialized()) |
| 110 int height = browser->override_bounds().height(); | 75 AddExistingPanel(panel); |
| 76 else |
| 77 AddNewPanel(panel); |
| 78 panels_.push_back(panel); |
| 79 } |
| 111 | 80 |
| 112 Panel* panel = new Panel(browser, gfx::Size(width, height)); | 81 void PanelStrip::AddNewPanel(Panel* panel) { |
| 82 DCHECK(!panel->initialized()); |
| 113 | 83 |
| 114 int max_panel_width = GetMaxPanelWidth(); | 84 int max_panel_width = GetMaxPanelWidth(); |
| 115 int max_panel_height = GetMaxPanelHeight(); | 85 int max_panel_height = GetMaxPanelHeight(); |
| 116 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), | 86 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), |
| 117 gfx::Size(max_panel_width, max_panel_height)); | 87 gfx::Size(max_panel_width, max_panel_height)); |
| 118 | 88 |
| 119 // Auto resizable is enabled only if no initial size is provided. | 89 gfx::Size restored_size = panel->restored_size(); |
| 120 bool auto_resize = (width == 0 && height == 0); | 90 int height = restored_size.height(); |
| 121 panel->SetAutoResizable(auto_resize); | 91 int width = restored_size.width(); |
| 122 | 92 |
| 123 // Adjust the width and height to fit into our constraint. | 93 if (height == 0 && width == 0) { |
| 124 if (!auto_resize) { | 94 // Auto resizable is enabled only if no initial size is provided. |
| 95 panel->SetAutoResizable(true); |
| 96 } else { |
| 125 if (height == 0) | 97 if (height == 0) |
| 126 height = width / kPanelDefaultWidthToHeightRatio; | 98 height = width / kPanelDefaultWidthToHeightRatio; |
| 127 if (width == 0) | 99 if (width == 0) |
| 128 width = height * kPanelDefaultWidthToHeightRatio; | 100 width = height * kPanelDefaultWidthToHeightRatio; |
| 129 } | 101 } |
| 130 | 102 |
| 103 // Constrain sizes to limits. |
| 131 if (width < kPanelMinWidth) | 104 if (width < kPanelMinWidth) |
| 132 width = kPanelMinWidth; | 105 width = kPanelMinWidth; |
| 133 else if (width > max_panel_width) | 106 else if (width > max_panel_width) |
| 134 width = max_panel_width; | 107 width = max_panel_width; |
| 135 | 108 |
| 136 if (height < kPanelMinHeight) | 109 if (height < kPanelMinHeight) |
| 137 height = kPanelMinHeight; | 110 height = kPanelMinHeight; |
| 138 else if (height > max_panel_height) | 111 else if (height > max_panel_height) |
| 139 height = max_panel_height; | 112 height = max_panel_height; |
| 140 | |
| 141 panel->set_restored_size(gfx::Size(width, height)); | 113 panel->set_restored_size(gfx::Size(width, height)); |
| 142 | 114 |
| 143 // Layout the new panel. | 115 // Layout the new panel. |
| 144 int y = adjusted_work_area_.bottom() - height; | 116 int y = strip_bounds_.bottom() - height; |
| 145 int x = GetRightMostAvailablePosition() - width; | 117 int x = GetRightMostAvailablePosition() - width; |
| 146 panel->Initialize(gfx::Rect(x, y, width, height)); | 118 panel->Initialize(gfx::Rect(x, y, width, height)); |
| 147 | |
| 148 panels_.push_back(panel); | |
| 149 | |
| 150 content::NotificationService::current()->Notify( | |
| 151 chrome::NOTIFICATION_PANEL_ADDED, | |
| 152 content::Source<Panel>(panel), | |
| 153 content::NotificationService::NoDetails()); | |
| 154 | |
| 155 return panel; | |
| 156 } | 119 } |
| 157 | 120 |
| 158 int PanelManager::GetMaxPanelWidth() const { | 121 void PanelStrip::AddExistingPanel(Panel* panel) { |
| 159 return static_cast<int>(adjusted_work_area_.width() * kPanelMaxWidthFactor); | 122 gfx::Size restored_size = panel->restored_size(); |
| 123 int height = restored_size.height(); |
| 124 int width = restored_size.width(); |
| 125 int x = GetRightMostAvailablePosition() - width; |
| 126 int y = strip_bounds_.bottom() - height; |
| 127 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); |
| 160 } | 128 } |
| 161 | 129 |
| 162 int PanelManager::GetMaxPanelHeight() const { | 130 int PanelStrip::GetMaxPanelWidth() const { |
| 163 return static_cast<int>(adjusted_work_area_.height() * kPanelMaxHeightFactor); | 131 return static_cast<int>(strip_bounds_.width() * kPanelMaxWidthFactor); |
| 164 } | 132 } |
| 165 | 133 |
| 166 int PanelManager::StartingRightPosition() const { | 134 int PanelStrip::GetMaxPanelHeight() const { |
| 167 return adjusted_work_area_.right() - kRightScreenEdgeSpacingWidth; | 135 return strip_bounds_.height(); |
| 168 } | 136 } |
| 169 | 137 |
| 170 int PanelManager::GetRightMostAvailablePosition() const { | 138 int PanelStrip::StartingRightPosition() const { |
| 139 return strip_bounds_.right(); |
| 140 } |
| 141 |
| 142 int PanelStrip::GetRightMostAvailablePosition() const { |
| 171 return panels_.empty() ? StartingRightPosition() : | 143 return panels_.empty() ? StartingRightPosition() : |
| 172 (panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing); | 144 (panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing); |
| 173 } | 145 } |
| 174 | 146 |
| 175 void PanelManager::Remove(Panel* panel) { | 147 bool PanelStrip::Remove(Panel* panel) { |
| 148 if (find(panels_.begin(), panels_.end(), panel) == panels_.end()) |
| 149 return false; |
| 150 |
| 176 // If we're in the process of dragging, delay the removal. | 151 // If we're in the process of dragging, delay the removal. |
| 177 if (dragging_panel_index_ != kInvalidPanelIndex) { | 152 if (dragging_panel_index_ != kInvalidPanelIndex) { |
| 178 panels_pending_to_remove_.push_back(panel); | 153 panels_pending_to_remove_.push_back(panel); |
| 179 return; | 154 return true; |
| 180 } | 155 } |
| 181 | 156 |
| 182 DoRemove(panel); | 157 DoRemove(panel); |
| 158 return true; |
| 183 } | 159 } |
| 184 | 160 |
| 185 void PanelManager::DelayedRemove() { | 161 void PanelStrip::DelayedRemove() { |
| 186 for (size_t i = 0; i < panels_pending_to_remove_.size(); ++i) | 162 for (size_t i = 0; i < panels_pending_to_remove_.size(); ++i) |
| 187 DoRemove(panels_pending_to_remove_[i]); | 163 DoRemove(panels_pending_to_remove_[i]); |
| 188 panels_pending_to_remove_.clear(); | 164 panels_pending_to_remove_.clear(); |
| 189 } | 165 } |
| 190 | 166 |
| 191 void PanelManager::DoRemove(Panel* panel) { | 167 void PanelStrip::DoRemove(Panel* panel) { |
| 192 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); | 168 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); |
| 193 if (iter == panels_.end()) | 169 if (iter == panels_.end()) |
| 194 return; | 170 return; |
| 195 | 171 |
| 196 if (panel->expansion_state() != Panel::EXPANDED) | 172 if (panel->expansion_state() != Panel::EXPANDED) |
| 197 DecrementMinimizedPanels(); | 173 DecrementMinimizedPanels(); |
| 198 | 174 |
| 199 gfx::Rect bounds = (*iter)->GetBounds(); | 175 gfx::Rect bounds = (*iter)->GetBounds(); |
| 200 Rearrange(panels_.erase(iter), bounds.right()); | 176 Rearrange(panels_.erase(iter), bounds.right()); |
| 201 | 177 panel_manager_->OnPanelRemoved(panel); |
| 202 content::NotificationService::current()->Notify( | |
| 203 chrome::NOTIFICATION_PANEL_REMOVED, | |
| 204 content::Source<Panel>(panel), | |
| 205 content::NotificationService::NoDetails()); | |
| 206 } | 178 } |
| 207 | 179 |
| 208 void PanelManager::StartDragging(Panel* panel) { | 180 void PanelStrip::StartDragging(Panel* panel) { |
| 209 for (size_t i = 0; i < panels_.size(); ++i) { | 181 for (size_t i = 0; i < panels_.size(); ++i) { |
| 210 if (panels_[i] == panel) { | 182 if (panels_[i] == panel) { |
| 211 dragging_panel_index_ = i; | 183 dragging_panel_index_ = i; |
| 212 dragging_panel_bounds_ = panel->GetBounds(); | 184 dragging_panel_bounds_ = panel->GetBounds(); |
| 213 dragging_panel_original_x_ = dragging_panel_bounds_.x(); | 185 dragging_panel_original_x_ = dragging_panel_bounds_.x(); |
| 214 break; | 186 break; |
| 215 } | 187 } |
| 216 } | 188 } |
| 217 } | 189 } |
| 218 | 190 |
| 219 void PanelManager::Drag(int delta_x) { | 191 void PanelStrip::Drag(int delta_x) { |
| 220 DCHECK(dragging_panel_index_ != kInvalidPanelIndex); | 192 DCHECK(dragging_panel_index_ != kInvalidPanelIndex); |
| 221 | 193 |
| 222 if (!delta_x) | 194 if (!delta_x) |
| 223 return; | 195 return; |
| 224 | 196 |
| 225 // Moves this panel to the dragging position. | 197 // Moves this panel to the dragging position. |
| 226 Panel* dragging_panel = panels_[dragging_panel_index_]; | 198 Panel* dragging_panel = panels_[dragging_panel_index_]; |
| 227 gfx::Rect new_bounds(dragging_panel->GetBounds()); | 199 gfx::Rect new_bounds(dragging_panel->GetBounds()); |
| 228 new_bounds.set_x(new_bounds.x() + delta_x); | 200 new_bounds.set_x(new_bounds.x() + delta_x); |
| 229 dragging_panel->SetPanelBounds(new_bounds); | 201 dragging_panel->SetPanelBounds(new_bounds); |
| 230 | 202 |
| 231 // Checks and processes other affected panels. | 203 // Checks and processes other affected panels. |
| 232 if (delta_x > 0) | 204 if (delta_x > 0) |
| 233 DragRight(); | 205 DragRight(); |
| 234 else | 206 else |
| 235 DragLeft(); | 207 DragLeft(); |
| 236 } | 208 } |
| 237 | 209 |
| 238 void PanelManager::DragLeft() { | 210 void PanelStrip::DragLeft() { |
| 239 Panel* dragging_panel = panels_[dragging_panel_index_]; | 211 Panel* dragging_panel = panels_[dragging_panel_index_]; |
| 240 | 212 |
| 241 // This is the left corner of the dragging panel. We use it to check against | 213 // This is the left corner of the dragging panel. We use it to check against |
| 242 // all the panels on its left. | 214 // all the panels on its left. |
| 243 int dragging_panel_left_boundary = dragging_panel->GetBounds().x(); | 215 int dragging_panel_left_boundary = dragging_panel->GetBounds().x(); |
| 244 | 216 |
| 245 // This is the right corner which a panel will be moved to. | 217 // This is the right corner which a panel will be moved to. |
| 246 int current_panel_right_boundary = | 218 int current_panel_right_boundary = |
| 247 dragging_panel_bounds_.x() + dragging_panel_bounds_.width(); | 219 dragging_panel_bounds_.x() + dragging_panel_bounds_.width(); |
| 248 | 220 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 271 // Updates the position and index of dragging panel as the result of moving | 243 // Updates the position and index of dragging panel as the result of moving |
| 272 // other affected panels. | 244 // other affected panels. |
| 273 if (current_panel_index != dragging_panel_index_ + 1) { | 245 if (current_panel_index != dragging_panel_index_ + 1) { |
| 274 dragging_panel_bounds_.set_x(current_panel_right_boundary - | 246 dragging_panel_bounds_.set_x(current_panel_right_boundary - |
| 275 dragging_panel_bounds_.width()); | 247 dragging_panel_bounds_.width()); |
| 276 dragging_panel_index_ = current_panel_index - 1; | 248 dragging_panel_index_ = current_panel_index - 1; |
| 277 panels_[dragging_panel_index_] = dragging_panel; | 249 panels_[dragging_panel_index_] = dragging_panel; |
| 278 } | 250 } |
| 279 } | 251 } |
| 280 | 252 |
| 281 void PanelManager::DragRight() { | 253 void PanelStrip::DragRight() { |
| 282 Panel* dragging_panel = panels_[dragging_panel_index_]; | 254 Panel* dragging_panel = panels_[dragging_panel_index_]; |
| 283 | 255 |
| 284 // This is the right corner of the dragging panel. We use it to check against | 256 // This is the right corner of the dragging panel. We use it to check against |
| 285 // all the panels on its right. | 257 // all the panels on its right. |
| 286 int dragging_panel_right_boundary = dragging_panel->GetBounds().x() + | 258 int dragging_panel_right_boundary = dragging_panel->GetBounds().x() + |
| 287 dragging_panel->GetBounds().width() - 1; | 259 dragging_panel->GetBounds().width() - 1; |
| 288 | 260 |
| 289 // This is the left corner which a panel will be moved to. | 261 // This is the left corner which a panel will be moved to. |
| 290 int current_panel_left_boundary = dragging_panel_bounds_.x(); | 262 int current_panel_left_boundary = dragging_panel_bounds_.x(); |
| 291 | 263 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 313 | 285 |
| 314 // Updates the position and index of dragging panel as the result of moving | 286 // Updates the position and index of dragging panel as the result of moving |
| 315 // other affected panels. | 287 // other affected panels. |
| 316 if (current_panel_index != static_cast<int>(dragging_panel_index_) - 1) { | 288 if (current_panel_index != static_cast<int>(dragging_panel_index_) - 1) { |
| 317 dragging_panel_bounds_.set_x(current_panel_left_boundary); | 289 dragging_panel_bounds_.set_x(current_panel_left_boundary); |
| 318 dragging_panel_index_ = current_panel_index + 1; | 290 dragging_panel_index_ = current_panel_index + 1; |
| 319 panels_[dragging_panel_index_] = dragging_panel; | 291 panels_[dragging_panel_index_] = dragging_panel; |
| 320 } | 292 } |
| 321 } | 293 } |
| 322 | 294 |
| 323 void PanelManager::EndDragging(bool cancelled) { | 295 void PanelStrip::EndDragging(bool cancelled) { |
| 324 DCHECK(dragging_panel_index_ != kInvalidPanelIndex); | 296 DCHECK(dragging_panel_index_ != kInvalidPanelIndex); |
| 325 | 297 |
| 326 if (cancelled) { | 298 if (cancelled) { |
| 327 Drag(dragging_panel_original_x_ - | 299 Drag(dragging_panel_original_x_ - |
| 328 panels_[dragging_panel_index_]->GetBounds().x()); | 300 panels_[dragging_panel_index_]->GetBounds().x()); |
| 329 } else { | 301 } else { |
| 330 panels_[dragging_panel_index_]->SetPanelBounds( | 302 panels_[dragging_panel_index_]->SetPanelBounds( |
| 331 dragging_panel_bounds_); | 303 dragging_panel_bounds_); |
| 332 } | 304 } |
| 333 | 305 |
| 334 dragging_panel_index_ = kInvalidPanelIndex; | 306 dragging_panel_index_ = kInvalidPanelIndex; |
| 335 | 307 |
| 336 DelayedRemove(); | 308 DelayedRemove(); |
| 337 } | 309 } |
| 338 | 310 |
| 339 void PanelManager::OnPanelExpansionStateChanged( | 311 void PanelStrip::OnPanelExpansionStateChanged( |
| 340 Panel::ExpansionState old_state, Panel::ExpansionState new_state) { | 312 Panel::ExpansionState old_state, Panel::ExpansionState new_state) { |
| 341 DCHECK_NE(new_state, old_state); | 313 DCHECK_NE(new_state, old_state); |
| 342 switch (new_state) { | 314 switch (new_state) { |
| 343 case Panel::EXPANDED: | 315 case Panel::EXPANDED: |
| 344 DecrementMinimizedPanels(); | 316 DecrementMinimizedPanels(); |
| 345 break; | 317 break; |
| 346 case Panel::MINIMIZED: | 318 case Panel::MINIMIZED: |
| 347 case Panel::TITLE_ONLY: | 319 case Panel::TITLE_ONLY: |
| 348 if (old_state == Panel::EXPANDED) | 320 if (old_state == Panel::EXPANDED) |
| 349 IncrementMinimizedPanels(); | 321 IncrementMinimizedPanels(); |
| 350 break; | 322 break; |
| 351 default: | 323 default: |
| 352 break; | 324 break; |
| 353 } | 325 } |
| 354 } | 326 } |
| 355 | 327 |
| 356 void PanelManager::IncrementMinimizedPanels() { | 328 void PanelStrip::IncrementMinimizedPanels() { |
| 357 if (!mouse_watching_disabled_ && !minimized_panel_count_) | |
| 358 panel_mouse_watcher_->AddObserver(this); | |
| 359 minimized_panel_count_++; | 329 minimized_panel_count_++; |
| 330 if (minimized_panel_count_ == 1) |
| 331 panel_manager_->mouse_watcher()->AddObserver(this); |
| 360 DCHECK_LE(minimized_panel_count_, num_panels()); | 332 DCHECK_LE(minimized_panel_count_, num_panels()); |
| 361 } | 333 } |
| 362 | 334 |
| 363 void PanelManager::DecrementMinimizedPanels() { | 335 void PanelStrip::DecrementMinimizedPanels() { |
| 364 minimized_panel_count_--; | 336 minimized_panel_count_--; |
| 365 DCHECK_GE(minimized_panel_count_, 0); | 337 DCHECK_GE(minimized_panel_count_, 0); |
| 366 if (!mouse_watching_disabled_ && !minimized_panel_count_) | 338 if (minimized_panel_count_ == 0) |
| 367 panel_mouse_watcher_->RemoveObserver(this); | 339 panel_manager_->mouse_watcher()->RemoveObserver(this); |
| 368 } | 340 } |
| 369 | 341 |
| 370 void PanelManager::OnPreferredWindowSizeChanged( | 342 void PanelStrip::OnPreferredWindowSizeChanged( |
| 371 Panel* panel, const gfx::Size& preferred_window_size) { | 343 Panel* panel, const gfx::Size& preferred_window_size) { |
| 372 if (!auto_sizing_enabled_) | |
| 373 return; | |
| 374 | |
| 375 gfx::Rect bounds = panel->GetBounds(); | 344 gfx::Rect bounds = panel->GetBounds(); |
| 376 | 345 |
| 377 // The panel width: | 346 // The panel width: |
| 378 // * cannot grow or shrink to go beyond [min_width, max_width] | 347 // * cannot grow or shrink to go beyond [min_width, max_width] |
| 379 int new_width = preferred_window_size.width(); | 348 int new_width = preferred_window_size.width(); |
| 380 if (new_width > panel->max_size().width()) | 349 if (new_width > panel->max_size().width()) |
| 381 new_width = panel->max_size().width(); | 350 new_width = panel->max_size().width(); |
| 382 if (new_width < panel->min_size().width()) | 351 if (new_width < panel->min_size().width()) |
| 383 new_width = panel->min_size().width(); | 352 new_width = panel->min_size().width(); |
| 384 | 353 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 bounds.set_height(new_height); | 389 bounds.set_height(new_height); |
| 421 } | 390 } |
| 422 | 391 |
| 423 gfx::Size new_size = gfx::Size(new_width, new_height); | 392 gfx::Size new_size = gfx::Size(new_width, new_height); |
| 424 if (new_size != restored_size) | 393 if (new_size != restored_size) |
| 425 panel->set_restored_size(new_size); | 394 panel->set_restored_size(new_size); |
| 426 | 395 |
| 427 panel->SetPanelBounds(bounds); | 396 panel->SetPanelBounds(bounds); |
| 428 } | 397 } |
| 429 | 398 |
| 430 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { | 399 bool PanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
| 431 // We should always bring up the titlebar if the mouse is over the | 400 // We should always bring up the titlebar if the mouse is over the |
| 432 // visible auto-hiding bottom bar. | 401 // visible auto-hiding bottom bar. |
| 433 if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) && | 402 AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); |
| 434 auto_hiding_desktop_bar_->GetVisibility( | 403 if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) && |
| 435 AutoHidingDesktopBar::ALIGN_BOTTOM) == | 404 desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM) == |
| 436 AutoHidingDesktopBar::VISIBLE && | 405 AutoHidingDesktopBar::VISIBLE && |
| 437 mouse_y >= adjusted_work_area_.bottom()) | 406 mouse_y >= strip_bounds_.bottom()) |
| 438 return true; | 407 return true; |
| 439 | 408 |
| 440 for (Panels::const_iterator iter = panels_.begin(); | 409 for (Panels::const_iterator iter = panels_.begin(); |
| 441 iter != panels_.end(); ++iter) { | 410 iter != panels_.end(); ++iter) { |
| 442 if ((*iter)->ShouldBringUpTitlebar(mouse_x, mouse_y)) | 411 if ((*iter)->ShouldBringUpTitlebar(mouse_x, mouse_y)) |
| 443 return true; | 412 return true; |
| 444 } | 413 } |
| 445 return false; | 414 return false; |
| 446 } | 415 } |
| 447 | 416 |
| 448 void PanelManager::BringUpOrDownTitlebars(bool bring_up) { | 417 void PanelStrip::BringUpOrDownTitlebars(bool bring_up) { |
| 449 if (are_titlebars_up_ == bring_up) | 418 if (are_titlebars_up_ == bring_up) |
| 450 return; | 419 return; |
| 451 are_titlebars_up_ = bring_up; | 420 are_titlebars_up_ = bring_up; |
| 452 | 421 |
| 453 int task_delay_milliseconds = 0; | 422 int task_delay_milliseconds = 0; |
| 454 | 423 |
| 455 // If the auto-hiding bottom bar exists, delay the action until the bottom | 424 // If the auto-hiding bottom bar exists, delay the action until the bottom |
| 456 // bar is fully visible or hidden. We do not want both bottom bar and panel | 425 // bar is fully visible or hidden. We do not want both bottom bar and panel |
| 457 // titlebar to move at the same time but with different speeds. | 426 // titlebar to move at the same time but with different speeds. |
| 458 if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { | 427 AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); |
| 459 AutoHidingDesktopBar::Visibility visibility = auto_hiding_desktop_bar_-> | 428 if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { |
| 460 GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM); | 429 AutoHidingDesktopBar::Visibility visibility = |
| 430 desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM); |
| 461 if (visibility != (bring_up ? AutoHidingDesktopBar::VISIBLE | 431 if (visibility != (bring_up ? AutoHidingDesktopBar::VISIBLE |
| 462 : AutoHidingDesktopBar::HIDDEN)) { | 432 : AutoHidingDesktopBar::HIDDEN)) { |
| 463 // Occasionally some system, like Windows, might not bring up or down the | 433 // Occasionally some system, like Windows, might not bring up or down the |
| 464 // bottom bar when the mouse enters or leaves the bottom screen area. | 434 // bottom bar when the mouse enters or leaves the bottom screen area. |
| 465 // Thus, we schedule a delayed task to do the work if we do not receive | 435 // Thus, we schedule a delayed task to do the work if we do not receive |
| 466 // the bottom bar visibility change notification within a certain period | 436 // the bottom bar visibility change notification within a certain period |
| 467 // of time. | 437 // of time. |
| 468 task_delay_milliseconds = | 438 task_delay_milliseconds = |
| 469 kMaxMillisecondsWaitForBottomBarVisibilityChange; | 439 kMaxMillisecondsWaitForBottomBarVisibilityChange; |
| 470 } | 440 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 490 if (remove_delays_for_testing_) | 460 if (remove_delays_for_testing_) |
| 491 task_delay_milliseconds = 0; | 461 task_delay_milliseconds = 0; |
| 492 | 462 |
| 493 // If user moves the mouse in and out of mouse tracking area, we might have | 463 // If user moves the mouse in and out of mouse tracking area, we might have |
| 494 // previously posted but not yet dispatched task in the queue. New action | 464 // previously posted but not yet dispatched task in the queue. New action |
| 495 // should always 'reset' the delays so cancel any tasks that haven't run yet | 465 // should always 'reset' the delays so cancel any tasks that haven't run yet |
| 496 // and post a new one. | 466 // and post a new one. |
| 497 titlebar_action_factory_.InvalidateWeakPtrs(); | 467 titlebar_action_factory_.InvalidateWeakPtrs(); |
| 498 MessageLoop::current()->PostDelayedTask( | 468 MessageLoop::current()->PostDelayedTask( |
| 499 FROM_HERE, | 469 FROM_HERE, |
| 500 base::Bind(&PanelManager::DelayedBringUpOrDownTitlebarsCheck, | 470 base::Bind(&PanelStrip::DelayedBringUpOrDownTitlebarsCheck, |
| 501 titlebar_action_factory_.GetWeakPtr()), | 471 titlebar_action_factory_.GetWeakPtr()), |
| 502 task_delay_milliseconds); | 472 task_delay_milliseconds); |
| 503 } | 473 } |
| 504 | 474 |
| 505 void PanelManager::DelayedBringUpOrDownTitlebarsCheck() { | 475 void PanelStrip::DelayedBringUpOrDownTitlebarsCheck() { |
| 506 // Task was already processed or cancelled - bail out. | 476 // Task was already processed or cancelled - bail out. |
| 507 if (delayed_titlebar_action_ == NO_ACTION) | 477 if (delayed_titlebar_action_ == NO_ACTION) |
| 508 return; | 478 return; |
| 509 | 479 |
| 510 bool need_to_bring_up_titlebars = (delayed_titlebar_action_ == BRING_UP); | 480 bool need_to_bring_up_titlebars = (delayed_titlebar_action_ == BRING_UP); |
| 511 | 481 |
| 512 delayed_titlebar_action_ = NO_ACTION; | 482 delayed_titlebar_action_ = NO_ACTION; |
| 513 | 483 |
| 514 // Check if the action is still needed based on the latest mouse position. The | 484 // Check if the action is still needed based on the latest mouse position. The |
| 515 // user could move the mouse into the tracking area and then quickly move it | 485 // user could move the mouse into the tracking area and then quickly move it |
| 516 // out of the area. In case of this, cancel the action. | 486 // out of the area. In case of this, cancel the action. |
| 517 if (are_titlebars_up_ != need_to_bring_up_titlebars) | 487 if (are_titlebars_up_ != need_to_bring_up_titlebars) |
| 518 return; | 488 return; |
| 519 | 489 |
| 520 DoBringUpOrDownTitlebars(need_to_bring_up_titlebars); | 490 DoBringUpOrDownTitlebars(need_to_bring_up_titlebars); |
| 521 } | 491 } |
| 522 | 492 |
| 523 void PanelManager::DoBringUpOrDownTitlebars(bool bring_up) { | 493 void PanelStrip::DoBringUpOrDownTitlebars(bool bring_up) { |
| 524 for (Panels::const_iterator iter = panels_.begin(); | 494 for (Panels::const_iterator iter = panels_.begin(); |
| 525 iter != panels_.end(); ++iter) { | 495 iter != panels_.end(); ++iter) { |
| 526 Panel* panel = *iter; | 496 Panel* panel = *iter; |
| 527 | 497 |
| 528 // Skip any panel that is drawing the attention. | 498 // Skip any panel that is drawing the attention. |
| 529 if (panel->IsDrawingAttention()) | 499 if (panel->IsDrawingAttention()) |
| 530 continue; | 500 continue; |
| 531 | 501 |
| 532 if (bring_up) { | 502 if (bring_up) { |
| 533 if (panel->expansion_state() == Panel::MINIMIZED) | 503 if (panel->expansion_state() == Panel::MINIMIZED) |
| 534 panel->SetExpansionState(Panel::TITLE_ONLY); | 504 panel->SetExpansionState(Panel::TITLE_ONLY); |
| 535 } else { | 505 } else { |
| 536 if (panel->expansion_state() == Panel::TITLE_ONLY) | 506 if (panel->expansion_state() == Panel::TITLE_ONLY) |
| 537 panel->SetExpansionState(Panel::MINIMIZED); | 507 panel->SetExpansionState(Panel::MINIMIZED); |
| 538 } | 508 } |
| 539 } | 509 } |
| 540 } | 510 } |
| 541 | 511 |
| 542 void PanelManager::AdjustWorkAreaForAutoHidingDesktopBars() { | 512 int PanelStrip::GetBottomPositionForExpansionState( |
| 543 // Note that we do not care about the desktop bar aligned to the top edge | |
| 544 // since panels could not reach so high due to size constraint. | |
| 545 adjusted_work_area_ = work_area_; | |
| 546 if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_LEFT)) { | |
| 547 int space = auto_hiding_desktop_bar_->GetThickness( | |
| 548 AutoHidingDesktopBar::ALIGN_LEFT); | |
| 549 adjusted_work_area_.set_x(adjusted_work_area_.x() + space); | |
| 550 adjusted_work_area_.set_width(adjusted_work_area_.width() - space); | |
| 551 } | |
| 552 if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_RIGHT)) { | |
| 553 int space = auto_hiding_desktop_bar_->GetThickness( | |
| 554 AutoHidingDesktopBar::ALIGN_RIGHT); | |
| 555 adjusted_work_area_.set_width(adjusted_work_area_.width() - space); | |
| 556 } | |
| 557 } | |
| 558 | |
| 559 int PanelManager::GetBottomPositionForExpansionState( | |
| 560 Panel::ExpansionState expansion_state) const { | 513 Panel::ExpansionState expansion_state) const { |
| 561 int bottom = adjusted_work_area_.bottom(); | 514 int bottom = strip_bounds_.bottom(); |
| 562 // If there is an auto-hiding desktop bar aligned to the bottom edge, we need | 515 // If there is an auto-hiding desktop bar aligned to the bottom edge, we need |
| 563 // to move the title-only panel above the auto-hiding desktop bar. | 516 // to move the title-only panel above the auto-hiding desktop bar. |
| 517 AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); |
| 564 if (expansion_state == Panel::TITLE_ONLY && | 518 if (expansion_state == Panel::TITLE_ONLY && |
| 565 auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { | 519 desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { |
| 566 bottom -= auto_hiding_desktop_bar_->GetThickness( | 520 bottom -= desktop_bar->GetThickness(AutoHidingDesktopBar::ALIGN_BOTTOM); |
| 567 AutoHidingDesktopBar::ALIGN_BOTTOM); | |
| 568 } | 521 } |
| 569 | 522 |
| 570 return bottom; | 523 return bottom; |
| 571 } | 524 } |
| 572 | 525 |
| 573 BrowserWindow* PanelManager::GetNextBrowserWindowToActivate( | 526 void PanelStrip::OnMouseMove(const gfx::Point& mouse_position) { |
| 574 Panel* panel) const { | |
| 575 // Find the last active browser window that is not minimized. | |
| 576 BrowserList::const_reverse_iterator iter = BrowserList::begin_last_active(); | |
| 577 BrowserList::const_reverse_iterator end = BrowserList::end_last_active(); | |
| 578 for (; (iter != end); ++iter) { | |
| 579 Browser* browser = *iter; | |
| 580 if (panel->browser() != browser && !browser->window()->IsMinimized()) | |
| 581 return browser->window(); | |
| 582 } | |
| 583 | |
| 584 return NULL; | |
| 585 } | |
| 586 | |
| 587 void PanelManager::MoveToPanelStrip(Panel* panel) { | |
| 588 // TODO(jennb) - implement. | |
| 589 } | |
| 590 | |
| 591 void PanelManager::MoveToOverflowStrip(Panel* panel, bool is_new) { | |
| 592 // TODO(jianli) - implement. | |
| 593 } | |
| 594 | |
| 595 void PanelManager::OnMouseMove(const gfx::Point& mouse_position) { | |
| 596 bool bring_up_titlebars = ShouldBringUpTitlebars(mouse_position.x(), | 527 bool bring_up_titlebars = ShouldBringUpTitlebars(mouse_position.x(), |
| 597 mouse_position.y()); | 528 mouse_position.y()); |
| 598 BringUpOrDownTitlebars(bring_up_titlebars); | 529 BringUpOrDownTitlebars(bring_up_titlebars); |
| 599 } | 530 } |
| 600 | 531 |
| 601 void PanelManager::OnAutoHidingDesktopBarThicknessChanged() { | 532 void PanelStrip::OnAutoHidingDesktopBarVisibilityChanged( |
| 602 AdjustWorkAreaForAutoHidingDesktopBars(); | |
| 603 Rearrange(panels_.begin(), StartingRightPosition()); | |
| 604 } | |
| 605 | |
| 606 void PanelManager::OnAutoHidingDesktopBarVisibilityChanged( | |
| 607 AutoHidingDesktopBar::Alignment alignment, | 533 AutoHidingDesktopBar::Alignment alignment, |
| 608 AutoHidingDesktopBar::Visibility visibility) { | 534 AutoHidingDesktopBar::Visibility visibility) { |
| 609 if (delayed_titlebar_action_ == NO_ACTION) | 535 if (delayed_titlebar_action_ == NO_ACTION) |
| 610 return; | 536 return; |
| 611 | 537 |
| 612 AutoHidingDesktopBar::Visibility expected_visibility = | 538 AutoHidingDesktopBar::Visibility expected_visibility = |
| 613 delayed_titlebar_action_ == BRING_UP ? AutoHidingDesktopBar::VISIBLE | 539 delayed_titlebar_action_ == BRING_UP ? AutoHidingDesktopBar::VISIBLE |
| 614 : AutoHidingDesktopBar::HIDDEN; | 540 : AutoHidingDesktopBar::HIDDEN; |
| 615 if (visibility != expected_visibility) | 541 if (visibility != expected_visibility) |
| 616 return; | 542 return; |
| 617 | 543 |
| 618 DoBringUpOrDownTitlebars(delayed_titlebar_action_ == BRING_UP); | 544 DoBringUpOrDownTitlebars(delayed_titlebar_action_ == BRING_UP); |
| 619 delayed_titlebar_action_ = NO_ACTION; | 545 delayed_titlebar_action_ = NO_ACTION; |
| 620 } | 546 } |
| 621 | 547 |
| 622 void PanelManager::Rearrange(Panels::iterator iter_to_start, | 548 void PanelStrip::Rearrange(Panels::iterator iter_to_start, |
| 623 int rightmost_position) { | 549 int rightmost_position) { |
| 624 for (Panels::iterator iter = iter_to_start; iter != panels_.end(); ++iter) { | 550 for (Panels::iterator iter = iter_to_start; iter != panels_.end(); ++iter) { |
| 625 Panel* panel = *iter; | 551 Panel* panel = *iter; |
| 626 gfx::Rect new_bounds(panel->GetBounds()); | 552 gfx::Rect new_bounds(panel->GetBounds()); |
| 627 new_bounds.set_x(rightmost_position - new_bounds.width()); | 553 new_bounds.set_x(rightmost_position - new_bounds.width()); |
| 628 new_bounds.set_y( | 554 new_bounds.set_y( |
| 629 GetBottomPositionForExpansionState(panel->expansion_state()) - | 555 GetBottomPositionForExpansionState(panel->expansion_state()) - |
| 630 new_bounds.height()); | 556 new_bounds.height()); |
| 631 if (new_bounds != panel->GetBounds()) | 557 panel->SetPanelBounds(new_bounds); |
| 632 panel->SetPanelBounds(new_bounds); | |
| 633 | 558 |
| 634 rightmost_position = new_bounds.x() - kPanelsHorizontalSpacing; | 559 rightmost_position = new_bounds.x() - kPanelsHorizontalSpacing; |
| 635 } | 560 } |
| 636 } | 561 } |
| 637 | 562 |
| 638 void PanelManager::RemoveAll() { | 563 void PanelStrip::RemoveAll() { |
| 639 // This should not be called when we're in the process of dragging. | 564 // This should not be called when we're in the process of dragging. |
| 640 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); | 565 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); |
| 641 | 566 |
| 642 // Make a copy of the iterator as closing panels can modify the vector. | 567 // Make a copy of the iterator as closing panels can modify the vector. |
| 643 Panels panels_copy = panels_; | 568 Panels panels_copy = panels_; |
| 644 | 569 |
| 645 // Start from the bottom to avoid reshuffling. | 570 // Start from the bottom to avoid reshuffling. |
| 646 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 571 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
| 647 iter != panels_copy.rend(); ++iter) | 572 iter != panels_copy.rend(); ++iter) |
| 648 (*iter)->Close(); | 573 (*iter)->Close(); |
| 649 } | 574 } |
| 650 | 575 |
| 651 bool PanelManager::is_dragging_panel() const { | 576 bool PanelStrip::is_dragging_panel() const { |
| 652 return dragging_panel_index_ != kInvalidPanelIndex; | 577 return dragging_panel_index_ != kInvalidPanelIndex; |
| 653 } | 578 } |
| OLD | NEW |