1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/panels/detached_panel_strip.h"
#include <algorithm>
#include "base/logging.h"
#include "chrome/browser/ui/panels/panel_drag_controller.h"
#include "chrome/browser/ui/panels/panel_manager.h"
DetachedPanelStrip::DetachedPanelStrip(PanelManager* panel_manager)
: PanelStrip(PanelStrip::DETACHED),
panel_manager_(panel_manager) {
}
DetachedPanelStrip::~DetachedPanelStrip() {
DCHECK(panels_.empty());
}
void DetachedPanelStrip::SetDisplayArea(const gfx::Rect& display_area) {
if (display_area_ == display_area)
return;
display_area_ = display_area;
if (panels_.empty())
return;
RefreshLayout();
}
void DetachedPanelStrip::RefreshLayout() {
// Nothing needds to be done here: detached panels always stay
// where the user dragged them.
}
void DetachedPanelStrip::AddPanel(Panel* panel,
PositioningMask positioning_mask) {
// positioning_mask is ignored since the detached panel is free-floating.
DCHECK_NE(this, panel->panel_strip());
panel->SetPanelStrip(this);
panels_.insert(panel);
}
void DetachedPanelStrip::RemovePanel(Panel* panel) {
DCHECK_EQ(this, panel->panel_strip());
panel->SetPanelStrip(NULL);
panels_.erase(panel);
}
void DetachedPanelStrip::CloseAll() {
// Make a copy as closing panels can modify the iterator.
Panels panels_copy = panels_;
for (Panels::const_iterator iter = panels_copy.begin();
iter != panels_copy.end(); ++iter)
(*iter)->Close();
}
void DetachedPanelStrip::OnPanelAttentionStateChanged(Panel* panel) {
DCHECK_EQ(this, panel->panel_strip());
// Nothing to do.
}
void DetachedPanelStrip::OnPanelTitlebarClicked(Panel* panel,
panel::ClickModifier modifier) {
DCHECK_EQ(this, panel->panel_strip());
// Click on detached panel titlebars does not do anything.
}
void DetachedPanelStrip::ResizePanelWindow(
Panel* panel,
const gfx::Size& preferred_window_size) {
// We should get this call only of we have the panel.
DCHECK_EQ(this, panel->panel_strip());
// Make sure the new size does not violate panel's size restrictions.
gfx::Size new_size(preferred_window_size.width(),
preferred_window_size.height());
panel->ClampSize(&new_size);
// Update restored size.
if (new_size != panel->restored_size())
panel->set_restored_size(new_size);
gfx::Rect bounds = panel->GetBounds();
// When we resize a detached panel, its origin does not move.
// So we set height and width only.
bounds.set_size(new_size);
if (bounds != panel->GetBounds())
panel->SetPanelBounds(bounds);
}
void DetachedPanelStrip::ActivatePanel(Panel* panel) {
DCHECK_EQ(this, panel->panel_strip());
// No change in panel's appearance.
}
void DetachedPanelStrip::MinimizePanel(Panel* panel) {
DCHECK_EQ(this, panel->panel_strip());
// Detached panels do not minimize. However, extensions may call this API
// regardless of which strip the panel is in. So we just quietly return.
}
void DetachedPanelStrip::RestorePanel(Panel* panel) {
DCHECK_EQ(this, panel->panel_strip());
// Detached panels do not minimize. However, extensions may call this API
// regardless of which strip the panel is in. So we just quietly return.
}
bool DetachedPanelStrip::IsPanelMinimized(const Panel* panel) const {
DCHECK_EQ(this, panel->panel_strip());
// Detached panels do not minimize.
return false;
}
bool DetachedPanelStrip::CanShowPanelAsActive(const Panel* panel) const {
// All detached panels can be shown as active.
return true;
}
void DetachedPanelStrip::SavePanelPlacement(Panel* panel) {
DCHECK(!saved_panel_placement_.panel);
saved_panel_placement_.panel = panel;
saved_panel_placement_.position = panel->GetBounds().origin();
}
void DetachedPanelStrip::RestorePanelToSavedPlacement() {
DCHECK(saved_panel_placement_.panel);
gfx::Rect new_bounds(saved_panel_placement_.panel->GetBounds());
new_bounds.set_origin(saved_panel_placement_.position);
saved_panel_placement_.panel->SetPanelBounds(new_bounds);
DiscardSavedPanelPlacement();
}
void DetachedPanelStrip::DiscardSavedPanelPlacement() {
DCHECK(saved_panel_placement_.panel);
saved_panel_placement_.panel = NULL;
}
bool DetachedPanelStrip::CanDragPanel(const Panel* panel) const {
// All detached panels are draggable.
return true;
}
void DetachedPanelStrip::StartDraggingPanelWithinStrip(Panel* panel) {
DCHECK(HasPanel(panel));
}
void DetachedPanelStrip::DragPanelWithinStrip(Panel* panel,
int delta_x,
int delta_y) {
gfx::Rect new_bounds(panel->GetBounds());
new_bounds.Offset(delta_x, delta_y);
panel->SetPanelBoundsInstantly(new_bounds);
}
void DetachedPanelStrip::EndDraggingPanelWithinStrip(Panel* panel,
bool aborted) {
}
bool DetachedPanelStrip::CanResizePanel(const Panel* panel) const {
return true;
}
void DetachedPanelStrip::SetPanelBounds(Panel* panel,
const gfx::Rect& new_bounds) {
DCHECK_EQ(this, panel->panel_strip());
panel->set_restored_size(new_bounds.size());
panel->SetPanelBoundsInstantly(new_bounds);
}
bool DetachedPanelStrip::HasPanel(Panel* panel) const {
return panels_.find(panel) != panels_.end();
}
void DetachedPanelStrip::UpdatePanelOnStripChange(Panel* panel) {
panel->set_attention_mode(
static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION |
Panel::USE_SYSTEM_ATTENTION));
panel->SetAlwaysOnTop(false);
panel->EnableResizeByMouse(true);
}
|