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/panel_browser_view.h" | 5 #include "chrome/browser/ui/panels/panel_browser_view.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/native_window_notification_source.h" | 9 #include "chrome/browser/native_window_notification_source.h" |
10 #include "chrome/browser/ui/panels/display_settings_provider.h" | 10 #include "chrome/browser/ui/panels/display_settings_provider.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "ui/views/controls/button/image_button.h" | 22 #include "ui/views/controls/button/image_button.h" |
23 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
24 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
25 | 25 |
26 #if defined(OS_WIN) && !defined(USE_AURA) | 26 #if defined(OS_WIN) && !defined(USE_AURA) |
27 #include "base/win/win_util.h" // for IsCtrlPressed() | 27 #include "base/win/win_util.h" // for IsCtrlPressed() |
28 #endif | 28 #endif |
29 | 29 |
30 using content::WebContents; | 30 using content::WebContents; |
31 | 31 |
32 namespace { | |
33 // The threshold to differentiate the short click and long click. | |
34 const int kShortClickThresholdMs = 200; | |
35 | |
36 // Delay before click-to-minimize is allowed after the attention has been | |
37 // cleared. | |
38 const int kSuspendMinimizeOnClickIntervalMs = 500; | |
39 } | |
40 | |
41 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, | 32 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, |
42 const gfx::Rect& bounds) { | 33 const gfx::Rect& bounds) { |
43 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); | 34 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); |
44 (new BrowserFrame(view))->InitBrowserFrame(); | 35 (new BrowserFrame(view))->InitBrowserFrame(); |
45 return view; | 36 return view; |
46 } | 37 } |
47 | 38 |
48 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, | 39 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, |
49 const gfx::Rect& bounds) | 40 const gfx::Rect& bounds) |
50 : BrowserView(browser), | 41 : BrowserView(browser), |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 GetFrameView()->GetWidget()->GetNativeView() == ::GetForegroundWindow(); | 172 GetFrameView()->GetWidget()->GetNativeView() == ::GetForegroundWindow(); |
182 #else | 173 #else |
183 NOTIMPLEMENTED(); | 174 NOTIMPLEMENTED(); |
184 bool focused = active; | 175 bool focused = active; |
185 #endif | 176 #endif |
186 | 177 |
187 if (focused_ == focused) | 178 if (focused_ == focused) |
188 return; | 179 return; |
189 focused_ = focused; | 180 focused_ = focused; |
190 | 181 |
191 if (focused_) { | 182 panel()->OnActiveStateChanged(focused); |
192 // Expand the panel if needed. Do NOT expand a TITLE_ONLY panel | |
193 // otherwise it will be impossible to drag a title without | |
194 // expanding it. | |
195 if (panel_->expansion_state() == Panel::MINIMIZED) | |
196 panel_->SetExpansionState(Panel::EXPANDED); | |
197 | |
198 if (is_drawing_attention_) { | |
199 panel_->FlashFrame(false); | |
200 | |
201 // Restore the panel from title-only mode here. Could not do this in the | |
202 // code above. | |
203 if (panel_->expansion_state() == Panel::TITLE_ONLY) | |
204 panel_->SetExpansionState(Panel::EXPANDED); | |
205 | |
206 // This function is called per one of the following user interactions: | |
207 // 1) clicking on the title-bar | |
208 // 2) clicking on the client area | |
209 // 3) switching to the panel via keyboard | |
210 // For case 1, we do not want the expanded panel to be minimized since the | |
211 // user clicks on it to mean to clear the attention. | |
212 attention_cleared_time_ = base::TimeTicks::Now(); | |
213 } | |
214 } | |
215 | |
216 content::NotificationService::current()->Notify( | |
217 chrome::NOTIFICATION_PANEL_CHANGED_ACTIVE_STATUS, | |
218 content::Source<Panel>(panel()), | |
219 content::NotificationService::NoDetails()); | |
220 panel()->OnActiveStateChanged(); | |
221 } | 183 } |
222 | 184 |
223 bool PanelBrowserView::AcceleratorPressed( | 185 bool PanelBrowserView::AcceleratorPressed( |
224 const ui::Accelerator& accelerator) { | 186 const ui::Accelerator& accelerator) { |
225 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) { | 187 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) { |
226 OnTitlebarMouseCaptureLost(); | 188 OnTitlebarMouseCaptureLost(); |
227 return true; | 189 return true; |
228 } | 190 } |
229 | 191 |
230 // No other accelerator is allowed when the drag begins. | 192 // No other accelerator is allowed when the drag begins. |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 #endif | 436 #endif |
475 } | 437 } |
476 | 438 |
477 PanelBrowserFrameView* PanelBrowserView::GetFrameView() const { | 439 PanelBrowserFrameView* PanelBrowserView::GetFrameView() const { |
478 return static_cast<PanelBrowserFrameView*>(frame()->GetFrameView()); | 440 return static_cast<PanelBrowserFrameView*>(frame()->GetFrameView()); |
479 } | 441 } |
480 | 442 |
481 bool PanelBrowserView::OnTitlebarMousePressed( | 443 bool PanelBrowserView::OnTitlebarMousePressed( |
482 const gfx::Point& mouse_location) { | 444 const gfx::Point& mouse_location) { |
483 mouse_pressed_ = true; | 445 mouse_pressed_ = true; |
484 mouse_pressed_time_ = base::TimeTicks::Now(); | |
485 mouse_dragging_state_ = NO_DRAGGING; | 446 mouse_dragging_state_ = NO_DRAGGING; |
486 last_mouse_location_ = mouse_location; | 447 last_mouse_location_ = mouse_location; |
487 return true; | 448 return true; |
488 } | 449 } |
489 | 450 |
490 bool PanelBrowserView::OnTitlebarMouseDragged( | 451 bool PanelBrowserView::OnTitlebarMouseDragged( |
491 const gfx::Point& mouse_location) { | 452 const gfx::Point& mouse_location) { |
492 if (!mouse_pressed_) | 453 if (!mouse_pressed_) |
493 return false; | 454 return false; |
494 | 455 |
(...skipping 13 matching lines...) Expand all Loading... |
508 panel_->manager()->Drag(mouse_location); | 469 panel_->manager()->Drag(mouse_location); |
509 | 470 |
510 // Once in drag, update |last_mouse_location_| on each drag fragment, since | 471 // Once in drag, update |last_mouse_location_| on each drag fragment, since |
511 // we already dragged the panel up to the current mouse location. | 472 // we already dragged the panel up to the current mouse location. |
512 last_mouse_location_ = mouse_location; | 473 last_mouse_location_ = mouse_location; |
513 } | 474 } |
514 return true; | 475 return true; |
515 } | 476 } |
516 | 477 |
517 bool PanelBrowserView::OnTitlebarMouseReleased() { | 478 bool PanelBrowserView::OnTitlebarMouseReleased() { |
518 if (mouse_dragging_state_ == DRAGGING_STARTED) { | 479 if (mouse_dragging_state_ != NO_DRAGGING) { |
519 // When a drag ends, restore the focus. | 480 // Ensure dragging a minimized panel does not leave it activated. |
520 if (old_focused_view_) { | 481 // Windows activates a panel on mouse-down, regardless of our attempts |
521 GetFocusManager()->SetFocusedView(old_focused_view_); | 482 // to prevent activation of a minimized panel. Now that we know mouse-down |
522 old_focused_view_ = NULL; | 483 // resulted in a mouse-drag, we need to ensure the minimized panel is |
| 484 // deactivated. |
| 485 if (panel_->IsMinimized() && panel_->IsActive()) |
| 486 panel_->Deactivate(); |
| 487 |
| 488 if (mouse_dragging_state_ == DRAGGING_STARTED) { |
| 489 // When a drag ends, restore the focus. |
| 490 if (old_focused_view_) { |
| 491 GetFocusManager()->SetFocusedView(old_focused_view_); |
| 492 old_focused_view_ = NULL; |
| 493 } |
| 494 return EndDragging(false); |
523 } | 495 } |
524 | 496 |
525 return EndDragging(false); | 497 // Else, the panel drag was cancelled before the mouse is released. Do not |
| 498 // treat this as a click. |
| 499 if (mouse_dragging_state_ != NO_DRAGGING) |
| 500 return true; |
526 } | 501 } |
527 | 502 |
528 // If the panel drag was cancelled before the mouse is released, do not treat | 503 panel::ClickModifier click_modifier = panel::NO_MODIFIER; |
529 // this as a click. | |
530 if (mouse_dragging_state_ != NO_DRAGGING) | |
531 return true; | |
532 | |
533 // Ignore long clicks. Treated as a canceled click to be consistent with Mac. | |
534 if (base::TimeTicks::Now() - mouse_pressed_time_ > | |
535 base::TimeDelta::FromMilliseconds(kShortClickThresholdMs)) | |
536 return true; | |
537 | |
538 #if defined(OS_WIN) && !defined(USE_AURA) | 504 #if defined(OS_WIN) && !defined(USE_AURA) |
539 if (base::win::IsCtrlPressed()) { | 505 if (base::win::IsCtrlPressed()) { |
540 panel_->OnTitlebarClicked(panel::APPLY_TO_ALL); | 506 click_modifier = panel::APPLY_TO_ALL; |
541 return true; | |
542 } | 507 } |
543 #else | 508 #else |
544 NOTIMPLEMENTED(); // Proceed without modifier. | 509 // Proceed without modifier. |
545 #endif | 510 #endif |
546 | 511 |
547 // TODO(jennb): Move remaining titlebar click handling out of here. | 512 panel_->OnTitlebarClicked(click_modifier); |
548 // (http://crbug.com/118431) | |
549 PanelStrip* panel_strip = panel_->panel_strip(); | |
550 if (!panel_strip) | |
551 return true; | |
552 | |
553 // Do not minimize the panel when we just clear the attention state. This is | |
554 // a hack to prevent the panel from being minimized when the user clicks on | |
555 // the title-bar to clear the attention. | |
556 if (panel_strip->type() == PanelStrip::DOCKED && | |
557 panel_->expansion_state() == Panel::EXPANDED && | |
558 base::TimeTicks::Now() - attention_cleared_time_ < | |
559 base::TimeDelta::FromMilliseconds(kSuspendMinimizeOnClickIntervalMs)) { | |
560 return true; | |
561 } | |
562 | |
563 if (panel_strip->type() == PanelStrip::DOCKED && | |
564 panel_->expansion_state() == Panel::EXPANDED) | |
565 panel_->SetExpansionState(Panel::MINIMIZED); | |
566 else | |
567 panel_->Activate(); | |
568 | |
569 return true; | 513 return true; |
570 } | 514 } |
571 | 515 |
572 bool PanelBrowserView::OnTitlebarMouseCaptureLost() { | 516 bool PanelBrowserView::OnTitlebarMouseCaptureLost() { |
573 if (mouse_dragging_state_ == DRAGGING_STARTED) | 517 if (mouse_dragging_state_ == DRAGGING_STARTED) |
574 return EndDragging(true); | 518 return EndDragging(true); |
575 return true; | 519 return true; |
576 } | 520 } |
577 | 521 |
578 bool PanelBrowserView::EndDragging(bool cancelled) { | 522 bool PanelBrowserView::EndDragging(bool cancelled) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 return frame_view->close_button_->visible(); | 704 return frame_view->close_button_->visible(); |
761 case MINIMIZE_BUTTON: | 705 case MINIMIZE_BUTTON: |
762 return frame_view->minimize_button_->visible(); | 706 return frame_view->minimize_button_->visible(); |
763 case RESTORE_BUTTON: | 707 case RESTORE_BUTTON: |
764 return frame_view->restore_button_->visible(); | 708 return frame_view->restore_button_->visible(); |
765 default: | 709 default: |
766 NOTREACHED(); | 710 NOTREACHED(); |
767 } | 711 } |
768 return false; | 712 return false; |
769 } | 713 } |
OLD | NEW |