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

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

Issue 7242017: Support minimizing the panel into 3-pixel line on Windows. Also support bringing up/down the titl... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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) 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_browser_view.h" 5 #include "chrome/browser/ui/panels/panel_browser_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/ui/panels/panel.h" 8 #include "chrome/browser/ui/panels/panel.h"
9 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" 9 #include "chrome/browser/ui/panels/panel_browser_frame_view.h"
10 #include "chrome/browser/ui/panels/panel_manager.h" 10 #include "chrome/browser/ui/panels/panel_manager.h"
11 #include "chrome/browser/ui/panels/panel_mouse_watcher_win.h"
11 #include "chrome/browser/ui/views/frame/browser_frame.h" 12 #include "chrome/browser/ui/views/frame/browser_frame.h"
12 #include "grit/chromium_strings.h" 13 #include "grit/chromium_strings.h"
13 #include "ui/base/animation/slide_animation.h" 14 #include "ui/base/animation/slide_animation.h"
14 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
15 #include "views/widget/widget.h" 16 #include "views/widget/widget.h"
16 17
17 namespace { 18 namespace {
18 // This value is experimental and subjective. 19 // This value is experimental and subjective.
19 const int kSetBoundsAnimationMs = 200; 20 const int kSetBoundsAnimationMs = 200;
21
22 // The panel can be fully minimized to 3-pixel lines.
23 const int kFullyMinimizedHeight = 3;
20 } 24 }
21 25
22 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, 26 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel,
23 const gfx::Rect& bounds) { 27 const gfx::Rect& bounds) {
24 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); 28 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds);
25 (new BrowserFrame(view))->InitBrowserFrame(); 29 (new BrowserFrame(view))->InitBrowserFrame();
26 return view; 30 return view;
27 } 31 }
28 32
29 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, 33 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel,
30 const gfx::Rect& bounds) 34 const gfx::Rect& bounds)
31 : BrowserView(browser), 35 : BrowserView(browser),
32 panel_(panel), 36 panel_(panel),
33 bounds_(bounds), 37 bounds_(bounds),
34 original_height_(bounds.height()), 38 original_height_(bounds.height()),
35 minimized_(false),
36 closed_(false), 39 closed_(false),
37 focused_(false), 40 focused_(false),
38 mouse_pressed_(false), 41 mouse_pressed_(false),
39 mouse_dragging_(false) { 42 mouse_dragging_(false) {
40 } 43 }
41 44
42 PanelBrowserView::~PanelBrowserView() { 45 PanelBrowserView::~PanelBrowserView() {
43 } 46 }
44 47
45 void PanelBrowserView::Init() { 48 void PanelBrowserView::Init() {
46 BrowserView::Init(); 49 BrowserView::Init();
47 50
48 GetWidget()->SetAlwaysOnTop(true); 51 GetWidget()->SetAlwaysOnTop(true);
49 GetWidget()->non_client_view()->SetAccessibleName( 52 GetWidget()->non_client_view()->SetAccessibleName(
50 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 53 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
51 } 54 }
52 55
53 void PanelBrowserView::Close() { 56 void PanelBrowserView::Close() {
54 closed_ = true; 57 closed_ = true;
55 58
56 // Cancel any currently running animation since we're closing down. 59 // Cancel any currently running animation since we're closing down.
57 if (bounds_animator_.get()) 60 if (bounds_animator_.get())
58 bounds_animator_.reset(); 61 bounds_animator_.reset();
59 62
60 ::BrowserView::Close(); 63 ::BrowserView::Close();
64
65 // Stop the global mouse watcher only if we do not have any panels up.
66 if (panel_->manager()->active_count())
jennb 2011/06/30 17:33:31 Should check for active count is 1? There must not
jianli 2011/06/30 18:22:36 Done. Also added test coverage.
67 StopMouseWatcher();
61 } 68 }
62 69
63 void PanelBrowserView::SetBounds(const gfx::Rect& bounds) { 70 void PanelBrowserView::SetBounds(const gfx::Rect& bounds) {
64 bounds_ = bounds; 71 bounds_ = bounds;
65 72
66 // No animation if the panel is being dragged. 73 // No animation if the panel is being dragged.
67 if (mouse_dragging_) { 74 if (mouse_dragging_) {
68 ::BrowserView::SetBounds(bounds); 75 ::BrowserView::SetBounds(bounds);
69 return; 76 return;
70 } 77 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 156 }
150 157
151 gfx::Rect PanelBrowserView::GetPanelBounds() const { 158 gfx::Rect PanelBrowserView::GetPanelBounds() const {
152 return bounds_; 159 return bounds_;
153 } 160 }
154 161
155 void PanelBrowserView::SetPanelBounds(const gfx::Rect& bounds) { 162 void PanelBrowserView::SetPanelBounds(const gfx::Rect& bounds) {
156 SetBounds(bounds); 163 SetBounds(bounds);
157 } 164 }
158 165
159 void PanelBrowserView::MinimizePanel() { 166 void PanelBrowserView::OnPanelExpansionStateChanged(
160 if (minimized_) 167 Panel::ExpansionState expansion_state) {
jennb 2011/06/30 17:33:31 Variable was named 'state' in .h. Should match nam
jianli 2011/06/30 18:22:36 Done.
161 return; 168 int height;
169 switch (expansion_state) {
170 case Panel::EXPANDED:
171 height = original_height_;
172 break;
173 case Panel::TITLE_ONLY:
174 height = GetFrameView()->NonClientTopBorderHeight();
175 break;
176 case Panel::MINIMIZED:
177 height = kFullyMinimizedHeight;
178 EnsureMouseWatcherStarted();
179 break;
180 default:
181 NOTREACHED();
182 height = original_height_;
183 break;
184 }
162 185
163 minimized_ = true; 186 gfx::Rect bounds = bounds_;
164 gfx::Rect bounds = GetPanelBounds(); 187 bounds.set_y(bounds.y() + bounds.height() - height);
165 original_height_ = bounds.height(); 188 bounds.set_height(height);
166 bounds.set_height(GetFrameView()->NonClientTopBorderHeight()); 189 SetBounds(bounds);
167 bounds.set_y(bounds.y() + original_height_ - bounds.height());
168 SetPanelBounds(bounds);
169 } 190 }
170 191
171 void PanelBrowserView::RestorePanel() { 192 bool PanelBrowserView::ShouldBringUpPanelTitleBar(int mouse_x,
172 if (!minimized_) 193 int mouse_y) const {
173 return; 194 return bounds_.x() <= mouse_x && mouse_x <= bounds_.right() &&
174 195 mouse_y >= bounds_.y();
175 minimized_ = false;
176 gfx::Rect bounds = GetPanelBounds();
177 bounds.set_y(bounds.y() - original_height_ + bounds.height());
178 bounds.set_height(original_height_);
179 SetPanelBounds(bounds);
180 } 196 }
181 197
182 void PanelBrowserView::ClosePanel() { 198 void PanelBrowserView::ClosePanel() {
183 Close(); 199 Close();
184 } 200 }
185 201
186 void PanelBrowserView::ActivatePanel() { 202 void PanelBrowserView::ActivatePanel() {
187 Activate(); 203 Activate();
188 } 204 }
189 205
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 260 }
245 if (mouse_dragging_) 261 if (mouse_dragging_)
246 panel_->manager()->Drag(delta_x); 262 panel_->manager()->Drag(delta_x);
247 return true; 263 return true;
248 } 264 }
249 265
250 bool PanelBrowserView::OnTitleBarMouseReleased(const views::MouseEvent& event) { 266 bool PanelBrowserView::OnTitleBarMouseReleased(const views::MouseEvent& event) {
251 if (mouse_dragging_) 267 if (mouse_dragging_)
252 return EndDragging(false); 268 return EndDragging(false);
253 269
254 MinimizeOrRestore(); 270 Panel::ExpansionState new_expansion_state =
271 (panel_->expansion_state() != Panel::EXPANDED) ? Panel::EXPANDED
jennb 2011/06/30 17:33:31 What if user clicks on the title bar in title-bar-
jianli 2011/06/30 18:22:36 The panel will be fully expanded.
272 : Panel::MINIMIZED;
273 panel_->SetExpansionState(new_expansion_state);
255 return true; 274 return true;
256 } 275 }
257 276
258 bool PanelBrowserView::OnTitleBarMouseCaptureLost() { 277 bool PanelBrowserView::OnTitleBarMouseCaptureLost() {
259 return EndDragging(true); 278 return EndDragging(true);
260 } 279 }
261 280
262 bool PanelBrowserView::EndDragging(bool cancelled) { 281 bool PanelBrowserView::EndDragging(bool cancelled) {
263 // Only handle clicks that started in our window. 282 // Only handle clicks that started in our window.
264 if (!mouse_pressed_) 283 if (!mouse_pressed_)
265 return false; 284 return false;
266 mouse_pressed_ = false; 285 mouse_pressed_ = false;
267 286
268 if (!mouse_dragging_) 287 if (!mouse_dragging_)
269 cancelled = true; 288 cancelled = true;
270 mouse_dragging_ = false; 289 mouse_dragging_ = false;
271 panel_->manager()->EndDragging(cancelled); 290 panel_->manager()->EndDragging(cancelled);
272 return true; 291 return true;
273 } 292 }
274
275 void PanelBrowserView::MinimizeOrRestore() {
276 if (minimized_)
277 panel_->Restore();
278 else
279 panel_->Minimize();
280 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698