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/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/events/event.h" | |
| 22 #include "ui/views/controls/button/image_button.h" | 23 #include "ui/views/controls/button/image_button.h" |
| 23 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
| 24 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 25 | 26 |
| 26 #if defined(OS_WIN) && !defined(USE_AURA) | |
| 27 #include "base/win/win_util.h" // for IsCtrlPressed() | |
| 28 #endif | |
| 29 | |
| 30 using content::WebContents; | 27 using content::WebContents; |
| 31 | 28 |
| 32 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, | 29 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, |
| 33 const gfx::Rect& bounds) { | 30 const gfx::Rect& bounds) { |
| 34 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); | 31 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); |
| 35 (new BrowserFrame(view))->InitBrowserFrame(); | 32 (new BrowserFrame(view))->InitBrowserFrame(); |
| 36 return view; | 33 return view; |
| 37 } | 34 } |
| 38 | 35 |
| 39 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, | 36 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); | 430 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); |
| 434 #else | 431 #else |
| 435 NOTIMPLEMENTED(); | 432 NOTIMPLEMENTED(); |
| 436 #endif | 433 #endif |
| 437 } | 434 } |
| 438 | 435 |
| 439 PanelBrowserFrameView* PanelBrowserView::GetFrameView() const { | 436 PanelBrowserFrameView* PanelBrowserView::GetFrameView() const { |
| 440 return static_cast<PanelBrowserFrameView*>(frame()->GetFrameView()); | 437 return static_cast<PanelBrowserFrameView*>(frame()->GetFrameView()); |
| 441 } | 438 } |
| 442 | 439 |
| 443 bool PanelBrowserView::OnTitlebarMousePressed( | 440 bool PanelBrowserView::OnTitlebarMousePressed(const views::MouseEvent& event) { |
| 444 const gfx::Point& mouse_location) { | 441 // |event.location| is in the view's coordinate system. Convert it to the |
| 442 // screen coordinate system. | |
| 443 gfx::Point mouse_location = event.location(); | |
| 444 views::View::ConvertPointToScreen(this, &mouse_location); | |
|
jianli
2012/04/27 22:32:10
|event| is for PanelBrowserFrameView, not PanelBro
jennb
2012/04/27 23:27:54
Changed to pass modifier around rather than event.
| |
| 445 | |
| 445 mouse_pressed_ = true; | 446 mouse_pressed_ = true; |
| 446 mouse_dragging_state_ = NO_DRAGGING; | 447 mouse_dragging_state_ = NO_DRAGGING; |
| 447 last_mouse_location_ = mouse_location; | 448 last_mouse_location_ = mouse_location; |
| 448 return true; | 449 return true; |
| 449 } | 450 } |
| 450 | 451 |
| 451 bool PanelBrowserView::OnTitlebarMouseDragged( | 452 bool PanelBrowserView::OnTitlebarMouseDragged(const views::MouseEvent& event) { |
| 452 const gfx::Point& mouse_location) { | |
| 453 if (!mouse_pressed_) | 453 if (!mouse_pressed_) |
| 454 return false; | 454 return false; |
| 455 | 455 |
| 456 // |event.location| is in the view's coordinate system. Convert it to the | |
| 457 // screen coordinate system. | |
| 458 gfx::Point mouse_location = event.location(); | |
| 459 views::View::ConvertPointToScreen(this, &mouse_location); | |
| 460 | |
| 456 int delta_x = mouse_location.x() - last_mouse_location_.x(); | 461 int delta_x = mouse_location.x() - last_mouse_location_.x(); |
| 457 int delta_y = mouse_location.y() - last_mouse_location_.y(); | 462 int delta_y = mouse_location.y() - last_mouse_location_.y(); |
| 458 if (mouse_dragging_state_ == NO_DRAGGING && | 463 if (mouse_dragging_state_ == NO_DRAGGING && |
| 459 ExceededDragThreshold(delta_x, delta_y)) { | 464 ExceededDragThreshold(delta_x, delta_y)) { |
| 460 // When a drag begins, we do not want to the client area to still receive | 465 // When a drag begins, we do not want to the client area to still receive |
| 461 // the focus. | 466 // the focus. |
| 462 old_focused_view_ = GetFocusManager()->GetFocusedView(); | 467 old_focused_view_ = GetFocusManager()->GetFocusedView(); |
| 463 GetFocusManager()->SetFocusedView(GetFrameView()); | 468 GetFocusManager()->SetFocusedView(GetFrameView()); |
| 464 | 469 |
| 465 panel_->manager()->StartDragging(panel_.get(), last_mouse_location_); | 470 panel_->manager()->StartDragging(panel_.get(), last_mouse_location_); |
| 466 mouse_dragging_state_ = DRAGGING_STARTED; | 471 mouse_dragging_state_ = DRAGGING_STARTED; |
| 467 } | 472 } |
| 468 if (mouse_dragging_state_ == DRAGGING_STARTED) { | 473 if (mouse_dragging_state_ == DRAGGING_STARTED) { |
| 469 panel_->manager()->Drag(mouse_location); | 474 panel_->manager()->Drag(mouse_location); |
| 470 | 475 |
| 471 // Once in drag, update |last_mouse_location_| on each drag fragment, since | 476 // Once in drag, update |last_mouse_location_| on each drag fragment, since |
| 472 // we already dragged the panel up to the current mouse location. | 477 // we already dragged the panel up to the current mouse location. |
| 473 last_mouse_location_ = mouse_location; | 478 last_mouse_location_ = mouse_location; |
| 474 } | 479 } |
| 475 return true; | 480 return true; |
| 476 } | 481 } |
| 477 | 482 |
| 478 bool PanelBrowserView::OnTitlebarMouseReleased() { | 483 bool PanelBrowserView::OnTitlebarMouseReleased(const views::MouseEvent& event) { |
| 479 if (mouse_dragging_state_ != NO_DRAGGING) { | 484 if (mouse_dragging_state_ != NO_DRAGGING) { |
| 480 // Ensure dragging a minimized panel does not leave it activated. | 485 // Ensure dragging a minimized panel does not leave it activated. |
| 481 // Windows activates a panel on mouse-down, regardless of our attempts | 486 // 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 | 487 // 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 | 488 // resulted in a mouse-drag, we need to ensure the minimized panel is |
| 484 // deactivated. | 489 // deactivated. |
| 485 if (panel_->IsMinimized() && panel_->IsActive()) | 490 if (panel_->IsMinimized() && panel_->IsActive()) |
| 486 panel_->Deactivate(); | 491 panel_->Deactivate(); |
| 487 | 492 |
| 488 if (mouse_dragging_state_ == DRAGGING_STARTED) { | 493 if (mouse_dragging_state_ == DRAGGING_STARTED) { |
| 489 // When a drag ends, restore the focus. | 494 // When a drag ends, restore the focus. |
| 490 if (old_focused_view_) { | 495 if (old_focused_view_) { |
| 491 GetFocusManager()->SetFocusedView(old_focused_view_); | 496 GetFocusManager()->SetFocusedView(old_focused_view_); |
| 492 old_focused_view_ = NULL; | 497 old_focused_view_ = NULL; |
| 493 } | 498 } |
| 494 return EndDragging(false); | 499 return EndDragging(false); |
| 495 } | 500 } |
| 496 | 501 |
| 497 // Else, the panel drag was cancelled before the mouse is released. Do not | 502 // Else, the panel drag was cancelled before the mouse is released. Do not |
| 498 // treat this as a click. | 503 // treat this as a click. |
| 499 if (mouse_dragging_state_ != NO_DRAGGING) | 504 if (mouse_dragging_state_ != NO_DRAGGING) |
| 500 return true; | 505 return true; |
| 501 } | 506 } |
| 502 | 507 |
| 503 panel::ClickModifier click_modifier = panel::NO_MODIFIER; | 508 panel_->OnTitlebarClicked( |
| 504 #if defined(OS_WIN) && !defined(USE_AURA) | 509 event.IsControlDown() ? panel::APPLY_TO_ALL : panel::NO_MODIFIER); |
| 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; | 510 return true; |
| 514 } | 511 } |
| 515 | 512 |
| 516 bool PanelBrowserView::OnTitlebarMouseCaptureLost() { | 513 bool PanelBrowserView::OnTitlebarMouseCaptureLost() { |
| 517 if (mouse_dragging_state_ == DRAGGING_STARTED) | 514 if (mouse_dragging_state_ == DRAGGING_STARTED) |
| 518 return EndDragging(true); | 515 return EndDragging(true); |
| 519 return true; | 516 return true; |
| 520 } | 517 } |
| 521 | 518 |
| 522 bool PanelBrowserView::EndDragging(bool cancelled) { | 519 bool PanelBrowserView::EndDragging(bool cancelled) { |
| 523 // Only handle clicks that started in our window. | 520 // Only handle clicks that started in our window. |
| 524 if (!mouse_pressed_) | 521 if (!mouse_pressed_) |
| 525 return false; | 522 return false; |
| 526 mouse_pressed_ = false; | 523 mouse_pressed_ = false; |
| 527 | 524 |
| 528 mouse_dragging_state_ = DRAGGING_ENDED; | 525 mouse_dragging_state_ = DRAGGING_ENDED; |
| 529 panel_->manager()->EndDragging(cancelled); | 526 panel_->manager()->EndDragging(cancelled); |
| 530 return true; | 527 return true; |
| 531 } | 528 } |
| 532 | 529 |
| 530 void PanelBrowserView::MinimizeButtonPressed(const views::Event& event) { | |
| 531 panel_->OnMinimizeButtonClicked( | |
| 532 event.IsControlDown() ? panel::APPLY_TO_ALL : panel::NO_MODIFIER); | |
| 533 } | |
| 534 | |
| 535 void PanelBrowserView::RestoreButtonPressed(const views::Event& event) { | |
| 536 panel_->OnRestoreButtonClicked( | |
| 537 event.IsControlDown() ? panel::APPLY_TO_ALL : panel::NO_MODIFIER); | |
| 538 } | |
| 539 | |
| 533 void PanelBrowserView::SetPanelAppIconVisibility(bool visible) { | 540 void PanelBrowserView::SetPanelAppIconVisibility(bool visible) { |
| 534 #if defined(OS_WIN) && !defined(USE_AURA) | 541 #if defined(OS_WIN) && !defined(USE_AURA) |
| 535 gfx::NativeWindow native_window = GetNativeHandle(); | 542 gfx::NativeWindow native_window = GetNativeHandle(); |
| 536 int style = ::GetWindowLong(native_window, GWL_EXSTYLE); | 543 int style = ::GetWindowLong(native_window, GWL_EXSTYLE); |
| 537 int new_style = style; | 544 int new_style = style; |
| 538 if (visible) | 545 if (visible) |
| 539 new_style &= (~WS_EX_TOOLWINDOW); | 546 new_style &= (~WS_EX_TOOLWINDOW); |
| 540 else | 547 else |
| 541 new_style |= WS_EX_TOOLWINDOW; | 548 new_style |= WS_EX_TOOLWINDOW; |
| 542 if (style != new_style) { | 549 if (style != new_style) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 | 615 |
| 609 NativePanelTestingWin::NativePanelTestingWin( | 616 NativePanelTestingWin::NativePanelTestingWin( |
| 610 PanelBrowserView* panel_browser_view) : | 617 PanelBrowserView* panel_browser_view) : |
| 611 panel_browser_view_(panel_browser_view) { | 618 panel_browser_view_(panel_browser_view) { |
| 612 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); | 619 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); |
| 613 frame_view->title_label_->SetAutoColorReadabilityEnabled(false); | 620 frame_view->title_label_->SetAutoColorReadabilityEnabled(false); |
| 614 } | 621 } |
| 615 | 622 |
| 616 void NativePanelTestingWin::PressLeftMouseButtonTitlebar( | 623 void NativePanelTestingWin::PressLeftMouseButtonTitlebar( |
| 617 const gfx::Point& mouse_location, panel::ClickModifier modifier) { | 624 const gfx::Point& mouse_location, panel::ClickModifier modifier) { |
| 618 #if defined(OS_WIN) && !defined(USE_AURA) | 625 int flags = ui::EF_LEFT_MOUSE_BUTTON; |
| 619 if (modifier == panel::APPLY_TO_ALL) { | 626 if (modifier == panel::APPLY_TO_ALL) |
| 620 BYTE keyState[256]; | 627 flags |= ui::EF_CONTROL_DOWN; |
| 621 ::GetKeyboardState(keyState); | 628 views::MouseEvent event(ui::ET_MOUSE_PRESSED, |
| 622 BYTE newKeyState[256]; | 629 mouse_location.x(), |
| 623 memcpy(newKeyState, keyState, sizeof(keyState)); | 630 mouse_location.y(), |
| 624 newKeyState[VK_CONTROL] = 0x80; | 631 flags); |
| 625 ::SetKeyboardState(newKeyState); | 632 panel_browser_view_->OnTitlebarMousePressed(event); |
| 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); | |
| 635 } | 633 } |
| 636 | 634 |
| 637 void NativePanelTestingWin::ReleaseMouseButtonTitlebar( | 635 void NativePanelTestingWin::ReleaseMouseButtonTitlebar( |
| 638 panel::ClickModifier modifier) { | 636 panel::ClickModifier modifier) { |
| 639 #if defined(OS_WIN) && !defined(USE_AURA) | 637 int flags = ui::EF_RIGHT_MOUSE_BUTTON; |
| 640 if (modifier == panel::APPLY_TO_ALL) { | 638 if (modifier == panel::APPLY_TO_ALL) |
| 641 BYTE keyState[256]; | 639 flags |= ui::EF_CONTROL_DOWN; |
| 642 ::GetKeyboardState(keyState); | 640 // Mouse location does not matter on button release. |
| 643 BYTE newKeyState[256]; | 641 views::MouseEvent event(ui::ET_MOUSE_RELEASED, |
| 644 memcpy(newKeyState, keyState, sizeof(keyState)); | 642 0, |
| 645 newKeyState[VK_CONTROL] = 0x80; | 643 0, |
| 646 ::SetKeyboardState(newKeyState); | 644 flags); |
| 647 panel_browser_view_->OnTitlebarMouseReleased(); | 645 panel_browser_view_->OnTitlebarMouseReleased(event); |
| 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 } | 646 } |
| 657 | 647 |
| 658 void NativePanelTestingWin::DragTitlebar(const gfx::Point& mouse_location) { | 648 void NativePanelTestingWin::DragTitlebar(const gfx::Point& mouse_location) { |
| 659 panel_browser_view_->OnTitlebarMouseDragged(mouse_location); | 649 views::MouseEvent event(ui::ET_MOUSE_PRESSED, |
| 650 mouse_location.x(), | |
| 651 mouse_location.y(), | |
| 652 ui::EF_LEFT_MOUSE_BUTTON); | |
| 653 panel_browser_view_->OnTitlebarMouseDragged(event); | |
| 660 } | 654 } |
| 661 | 655 |
| 662 void NativePanelTestingWin::CancelDragTitlebar() { | 656 void NativePanelTestingWin::CancelDragTitlebar() { |
| 663 panel_browser_view_->OnTitlebarMouseCaptureLost(); | 657 panel_browser_view_->OnTitlebarMouseCaptureLost(); |
| 664 } | 658 } |
| 665 | 659 |
| 666 void NativePanelTestingWin::FinishDragTitlebar() { | 660 void NativePanelTestingWin::FinishDragTitlebar() { |
| 667 panel_browser_view_->OnTitlebarMouseReleased(); | 661 ReleaseMouseButtonTitlebar(panel::NO_MODIFIER); |
| 668 } | 662 } |
| 669 | 663 |
| 670 bool NativePanelTestingWin::VerifyDrawingAttention() const { | 664 bool NativePanelTestingWin::VerifyDrawingAttention() const { |
| 671 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); | 665 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); |
| 672 SkColor attention_color = frame_view->GetTitleColor( | 666 SkColor attention_color = frame_view->GetTitleColor( |
| 673 PanelBrowserFrameView::PAINT_FOR_ATTENTION); | 667 PanelBrowserFrameView::PAINT_FOR_ATTENTION); |
| 674 return attention_color == frame_view->title_label_->enabled_color(); | 668 return attention_color == frame_view->title_label_->enabled_color(); |
| 675 } | 669 } |
| 676 | 670 |
| 677 bool NativePanelTestingWin::VerifyActiveState(bool is_active) { | 671 bool NativePanelTestingWin::VerifyActiveState(bool is_active) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 704 return frame_view->close_button_->visible(); | 698 return frame_view->close_button_->visible(); |
| 705 case MINIMIZE_BUTTON: | 699 case MINIMIZE_BUTTON: |
| 706 return frame_view->minimize_button_->visible(); | 700 return frame_view->minimize_button_->visible(); |
| 707 case RESTORE_BUTTON: | 701 case RESTORE_BUTTON: |
| 708 return frame_view->restore_button_->visible(); | 702 return frame_view->restore_button_->visible(); |
| 709 default: | 703 default: |
| 710 NOTREACHED(); | 704 NOTREACHED(); |
| 711 } | 705 } |
| 712 return false; | 706 return false; |
| 713 } | 707 } |
| OLD | NEW |