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/detached_panel_strip.h" | 5 #include "chrome/browser/ui/panels/detached_panel_strip.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/ui/panels/panel_drag_controller.h" | 9 #include "chrome/browser/ui/panels/panel_drag_controller.h" |
| 10 #include "chrome/browser/ui/panels/panel_manager.h" | 10 #include "chrome/browser/ui/panels/panel_manager.h" |
| 11 | 11 |
| 12 namespace { | |
| 13 // How much horizontal and vertical offset there is between newly opened | |
| 14 // detached panels. | |
| 15 const int kPanelTilePixels = 10; | |
| 16 } // namespace | |
| 17 | |
| 12 DetachedPanelStrip::DetachedPanelStrip(PanelManager* panel_manager) | 18 DetachedPanelStrip::DetachedPanelStrip(PanelManager* panel_manager) |
| 13 : PanelStrip(PanelStrip::DETACHED), | 19 : PanelStrip(PanelStrip::DETACHED), |
| 14 panel_manager_(panel_manager) { | 20 panel_manager_(panel_manager) { |
| 15 } | 21 } |
| 16 | 22 |
| 17 DetachedPanelStrip::~DetachedPanelStrip() { | 23 DetachedPanelStrip::~DetachedPanelStrip() { |
| 18 DCHECK(panels_.empty()); | 24 DCHECK(panels_.empty()); |
| 19 } | 25 } |
| 20 | 26 |
| 21 gfx::Rect DetachedPanelStrip::GetDisplayArea() const { | 27 gfx::Rect DetachedPanelStrip::GetDisplayArea() const { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 // Nothing needds to be done here: detached panels always stay | 65 // Nothing needds to be done here: detached panels always stay |
| 60 // where the user dragged them. | 66 // where the user dragged them. |
| 61 } | 67 } |
| 62 | 68 |
| 63 void DetachedPanelStrip::AddPanel(Panel* panel, | 69 void DetachedPanelStrip::AddPanel(Panel* panel, |
| 64 PositioningMask positioning_mask) { | 70 PositioningMask positioning_mask) { |
| 65 // positioning_mask is ignored since the detached panel is free-floating. | 71 // positioning_mask is ignored since the detached panel is free-floating. |
| 66 DCHECK_NE(this, panel->panel_strip()); | 72 DCHECK_NE(this, panel->panel_strip()); |
| 67 panel->set_panel_strip(this); | 73 panel->set_panel_strip(this); |
| 68 panels_.insert(panel); | 74 panels_.insert(panel); |
| 75 | |
| 76 // Offset the default position of the next detached panel if the current | |
| 77 // default position is used. | |
| 78 if (panel->GetBounds().origin() == default_panel_origin_) | |
| 79 OffsetDefaultPanelOrigin(); | |
| 69 } | 80 } |
| 70 | 81 |
| 71 void DetachedPanelStrip::RemovePanel(Panel* panel) { | 82 void DetachedPanelStrip::RemovePanel(Panel* panel) { |
| 72 DCHECK_EQ(this, panel->panel_strip()); | 83 DCHECK_EQ(this, panel->panel_strip()); |
| 73 panel->set_panel_strip(NULL); | 84 panel->set_panel_strip(NULL); |
| 74 panels_.erase(panel); | 85 panels_.erase(panel); |
| 75 } | 86 } |
| 76 | 87 |
| 77 void DetachedPanelStrip::CloseAll() { | 88 void DetachedPanelStrip::CloseAll() { |
| 78 // Make a copy as closing panels can modify the iterator. | 89 // Make a copy as closing panels can modify the iterator. |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION | | 232 static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION | |
| 222 Panel::USE_SYSTEM_ATTENTION)); | 233 Panel::USE_SYSTEM_ATTENTION)); |
| 223 panel->SetAlwaysOnTop(false); | 234 panel->SetAlwaysOnTop(false); |
| 224 panel->EnableResizeByMouse(true); | 235 panel->EnableResizeByMouse(true); |
| 225 panel->UpdateMinimizeRestoreButtonVisibility(); | 236 panel->UpdateMinimizeRestoreButtonVisibility(); |
| 226 } | 237 } |
| 227 | 238 |
| 228 void DetachedPanelStrip::OnPanelActiveStateChanged(Panel* panel) { | 239 void DetachedPanelStrip::OnPanelActiveStateChanged(Panel* panel) { |
| 229 } | 240 } |
| 230 | 241 |
| 242 gfx::Point DetachedPanelStrip::GetDefaultPanelOrigin() { | |
| 243 if (!default_panel_origin_.x() && !default_panel_origin_.y()) { | |
| 244 gfx::Rect display_area = | |
| 245 panel_manager_->display_settings_provider()->GetDisplayArea(); | |
| 246 default_panel_origin_.SetPoint(kPanelTilePixels + display_area.x(), | |
| 247 kPanelTilePixels + display_area.y()); | |
| 248 } | |
| 249 return default_panel_origin_; | |
| 250 } | |
| 251 | |
| 252 void DetachedPanelStrip::OffsetDefaultPanelOrigin() { | |
|
jianli
2012/09/05 20:21:40
nit: Probably better name like ComputeNextDefaultP
jennb
2012/09/05 21:11:07
Done.
| |
| 253 default_panel_origin_.Offset(kPanelTilePixels, kPanelTilePixels); | |
| 254 gfx::Rect display_area = | |
| 255 panel_manager_->display_settings_provider()->GetDisplayArea(); | |
| 256 if (!display_area.Contains(default_panel_origin_)) { | |
| 257 default_panel_origin_.SetPoint(kPanelTilePixels + display_area.x(), | |
| 258 kPanelTilePixels + display_area.y()); | |
| 259 } | |
| 260 } | |
| OLD | NEW |