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

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

Issue 10187021: Add key modifier to minimize/restore button click to minimize/restore-all panels for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pass modifier instead of event around. Created 8 years, 8 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) 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"
11 #include "chrome/browser/ui/panels/panel.h" 11 #include "chrome/browser/ui/panels/panel.h"
12 #include "chrome/browser/ui/panels/panel_bounds_animation.h" 12 #include "chrome/browser/ui/panels/panel_bounds_animation.h"
13 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" 13 #include "chrome/browser/ui/panels/panel_browser_frame_view.h"
14 #include "chrome/browser/ui/panels/panel_manager.h" 14 #include "chrome/browser/ui/panels/panel_manager.h"
15 #include "chrome/browser/ui/panels/panel_strip.h" 15 #include "chrome/browser/ui/panels/panel_strip.h"
16 #include "chrome/browser/ui/views/frame/browser_frame.h" 16 #include "chrome/browser/ui/views/frame/browser_frame.h"
17 #include "chrome/browser/ui/webui/task_manager/task_manager_dialog.h" 17 #include "chrome/browser/ui/webui/task_manager/task_manager_dialog.h"
18 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
19 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
20 #include "grit/chromium_strings.h" 20 #include "grit/chromium_strings.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
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)
27 #include "base/win/win_util.h" // for IsCtrlPressed()
28 #endif
29
30 using content::WebContents; 26 using content::WebContents;
31 27
32 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, 28 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel,
33 const gfx::Rect& bounds) { 29 const gfx::Rect& bounds) {
34 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); 30 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds);
35 (new BrowserFrame(view))->InitBrowserFrame(); 31 (new BrowserFrame(view))->InitBrowserFrame();
36 return view; 32 return view;
37 } 33 }
38 34
39 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, 35 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel,
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 if (mouse_dragging_state_ == DRAGGING_STARTED) { 464 if (mouse_dragging_state_ == DRAGGING_STARTED) {
469 panel_->manager()->Drag(mouse_location); 465 panel_->manager()->Drag(mouse_location);
470 466
471 // Once in drag, update |last_mouse_location_| on each drag fragment, since 467 // Once in drag, update |last_mouse_location_| on each drag fragment, since
472 // we already dragged the panel up to the current mouse location. 468 // we already dragged the panel up to the current mouse location.
473 last_mouse_location_ = mouse_location; 469 last_mouse_location_ = mouse_location;
474 } 470 }
475 return true; 471 return true;
476 } 472 }
477 473
478 bool PanelBrowserView::OnTitlebarMouseReleased() { 474 bool PanelBrowserView::OnTitlebarMouseReleased(panel::ClickModifier modifier) {
479 if (mouse_dragging_state_ != NO_DRAGGING) { 475 if (mouse_dragging_state_ != NO_DRAGGING) {
480 // Ensure dragging a minimized panel does not leave it activated. 476 // Ensure dragging a minimized panel does not leave it activated.
481 // Windows activates a panel on mouse-down, regardless of our attempts 477 // Windows activates a panel on mouse-down, regardless of our attempts
482 // to prevent activation of a minimized panel. Now that we know mouse-down 478 // to prevent activation of a minimized panel. Now that we know mouse-down
483 // resulted in a mouse-drag, we need to ensure the minimized panel is 479 // resulted in a mouse-drag, we need to ensure the minimized panel is
484 // deactivated. 480 // deactivated.
485 if (panel_->IsMinimized() && panel_->IsActive()) 481 if (panel_->IsMinimized() && panel_->IsActive())
486 panel_->Deactivate(); 482 panel_->Deactivate();
487 483
488 if (mouse_dragging_state_ == DRAGGING_STARTED) { 484 if (mouse_dragging_state_ == DRAGGING_STARTED) {
489 // When a drag ends, restore the focus. 485 // When a drag ends, restore the focus.
490 if (old_focused_view_) { 486 if (old_focused_view_) {
491 GetFocusManager()->SetFocusedView(old_focused_view_); 487 GetFocusManager()->SetFocusedView(old_focused_view_);
492 old_focused_view_ = NULL; 488 old_focused_view_ = NULL;
493 } 489 }
494 return EndDragging(false); 490 return EndDragging(false);
495 } 491 }
496 492
497 // Else, the panel drag was cancelled before the mouse is released. Do not 493 // Else, the panel drag was cancelled before the mouse is released. Do not
498 // treat this as a click. 494 // treat this as a click.
499 if (mouse_dragging_state_ != NO_DRAGGING) 495 if (mouse_dragging_state_ != NO_DRAGGING)
500 return true; 496 return true;
501 } 497 }
502 498
503 panel::ClickModifier click_modifier = panel::NO_MODIFIER; 499 panel_->OnTitlebarClicked(modifier);
504 #if defined(OS_WIN) && !defined(USE_AURA)
505 if (base::win::IsCtrlPressed()) {
506 click_modifier = panel::APPLY_TO_ALL;
507 }
508 #else
509 // Proceed without modifier.
510 #endif
511
512 panel_->OnTitlebarClicked(click_modifier);
513 return true; 500 return true;
514 } 501 }
515 502
516 bool PanelBrowserView::OnTitlebarMouseCaptureLost() { 503 bool PanelBrowserView::OnTitlebarMouseCaptureLost() {
517 if (mouse_dragging_state_ == DRAGGING_STARTED) 504 if (mouse_dragging_state_ == DRAGGING_STARTED)
518 return EndDragging(true); 505 return EndDragging(true);
519 return true; 506 return true;
520 } 507 }
521 508
522 bool PanelBrowserView::EndDragging(bool cancelled) { 509 bool PanelBrowserView::EndDragging(bool cancelled) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 595
609 NativePanelTestingWin::NativePanelTestingWin( 596 NativePanelTestingWin::NativePanelTestingWin(
610 PanelBrowserView* panel_browser_view) : 597 PanelBrowserView* panel_browser_view) :
611 panel_browser_view_(panel_browser_view) { 598 panel_browser_view_(panel_browser_view) {
612 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); 599 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView();
613 frame_view->title_label_->SetAutoColorReadabilityEnabled(false); 600 frame_view->title_label_->SetAutoColorReadabilityEnabled(false);
614 } 601 }
615 602
616 void NativePanelTestingWin::PressLeftMouseButtonTitlebar( 603 void NativePanelTestingWin::PressLeftMouseButtonTitlebar(
617 const gfx::Point& mouse_location, panel::ClickModifier modifier) { 604 const gfx::Point& mouse_location, panel::ClickModifier modifier) {
618 #if defined(OS_WIN) && !defined(USE_AURA)
619 if (modifier == panel::APPLY_TO_ALL) {
620 BYTE keyState[256];
621 ::GetKeyboardState(keyState);
622 BYTE newKeyState[256];
623 memcpy(newKeyState, keyState, sizeof(keyState));
624 newKeyState[VK_CONTROL] = 0x80;
625 ::SetKeyboardState(newKeyState);
626 panel_browser_view_->OnTitlebarMousePressed(mouse_location);
627 ::SetKeyboardState(keyState); // restore to original
628 return;
629 }
630 #else
631 // Cannot test with modifier. Proceed without it.
632 #endif
633
634 panel_browser_view_->OnTitlebarMousePressed(mouse_location); 605 panel_browser_view_->OnTitlebarMousePressed(mouse_location);
635 } 606 }
636 607
637 void NativePanelTestingWin::ReleaseMouseButtonTitlebar( 608 void NativePanelTestingWin::ReleaseMouseButtonTitlebar(
638 panel::ClickModifier modifier) { 609 panel::ClickModifier modifier) {
639 #if defined(OS_WIN) && !defined(USE_AURA) 610 panel_browser_view_->OnTitlebarMouseReleased(modifier);
640 if (modifier == panel::APPLY_TO_ALL) {
641 BYTE keyState[256];
642 ::GetKeyboardState(keyState);
643 BYTE newKeyState[256];
644 memcpy(newKeyState, keyState, sizeof(keyState));
645 newKeyState[VK_CONTROL] = 0x80;
646 ::SetKeyboardState(newKeyState);
647 panel_browser_view_->OnTitlebarMouseReleased();
648 ::SetKeyboardState(keyState); // restore to original
649 return;
650 }
651 #else
652 // Cannot test with modifier. Proceed without it.
653 #endif
654
655 panel_browser_view_->OnTitlebarMouseReleased();
656 } 611 }
657 612
658 void NativePanelTestingWin::DragTitlebar(const gfx::Point& mouse_location) { 613 void NativePanelTestingWin::DragTitlebar(const gfx::Point& mouse_location) {
659 panel_browser_view_->OnTitlebarMouseDragged(mouse_location); 614 panel_browser_view_->OnTitlebarMouseDragged(mouse_location);
660 } 615 }
661 616
662 void NativePanelTestingWin::CancelDragTitlebar() { 617 void NativePanelTestingWin::CancelDragTitlebar() {
663 panel_browser_view_->OnTitlebarMouseCaptureLost(); 618 panel_browser_view_->OnTitlebarMouseCaptureLost();
664 } 619 }
665 620
666 void NativePanelTestingWin::FinishDragTitlebar() { 621 void NativePanelTestingWin::FinishDragTitlebar() {
667 panel_browser_view_->OnTitlebarMouseReleased(); 622 panel_browser_view_->OnTitlebarMouseReleased(panel::NO_MODIFIER);
668 } 623 }
669 624
670 bool NativePanelTestingWin::VerifyDrawingAttention() const { 625 bool NativePanelTestingWin::VerifyDrawingAttention() const {
671 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); 626 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView();
672 SkColor attention_color = frame_view->GetTitleColor( 627 SkColor attention_color = frame_view->GetTitleColor(
673 PanelBrowserFrameView::PAINT_FOR_ATTENTION); 628 PanelBrowserFrameView::PAINT_FOR_ATTENTION);
674 return attention_color == frame_view->title_label_->enabled_color(); 629 return attention_color == frame_view->title_label_->enabled_color();
675 } 630 }
676 631
677 bool NativePanelTestingWin::VerifyActiveState(bool is_active) { 632 bool NativePanelTestingWin::VerifyActiveState(bool is_active) {
(...skipping 26 matching lines...) Expand all
704 return frame_view->close_button_->visible(); 659 return frame_view->close_button_->visible();
705 case MINIMIZE_BUTTON: 660 case MINIMIZE_BUTTON:
706 return frame_view->minimize_button_->visible(); 661 return frame_view->minimize_button_->visible();
707 case RESTORE_BUTTON: 662 case RESTORE_BUTTON:
708 return frame_view->restore_button_->visible(); 663 return frame_view->restore_button_->visible();
709 default: 664 default:
710 NOTREACHED(); 665 NOTREACHED();
711 } 666 }
712 return false; 667 return false;
713 } 668 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_browser_view.h ('k') | chrome/browser/ui/panels/panel_browser_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698