| 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/panel.h" | 10 #include "chrome/browser/ui/panels/panel.h" |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 | 455 |
| 456 int delta_x = mouse_location_.x() - last_mouse_location.x(); | 456 int delta_x = mouse_location_.x() - last_mouse_location.x(); |
| 457 int delta_y = mouse_location_.y() - last_mouse_location.y(); | 457 int delta_y = mouse_location_.y() - last_mouse_location.y(); |
| 458 if (mouse_dragging_state_ == NO_DRAGGING && | 458 if (mouse_dragging_state_ == NO_DRAGGING && |
| 459 ExceededDragThreshold(delta_x, delta_y)) { | 459 ExceededDragThreshold(delta_x, delta_y)) { |
| 460 // When a drag begins, we do not want to the client area to still receive | 460 // When a drag begins, we do not want to the client area to still receive |
| 461 // the focus. | 461 // the focus. |
| 462 old_focused_view_ = GetFocusManager()->GetFocusedView(); | 462 old_focused_view_ = GetFocusManager()->GetFocusedView(); |
| 463 GetFocusManager()->SetFocusedView(GetFrameView()); | 463 GetFocusManager()->SetFocusedView(GetFrameView()); |
| 464 | 464 |
| 465 panel_->manager()->StartDragging(panel_.get()); | 465 panel_->manager()->StartDragging(panel_.get(), last_mouse_location); |
| 466 mouse_dragging_state_ = DRAGGING_STARTED; | 466 mouse_dragging_state_ = DRAGGING_STARTED; |
| 467 } | 467 } |
| 468 if (mouse_dragging_state_ == DRAGGING_STARTED) | 468 if (mouse_dragging_state_ == DRAGGING_STARTED) |
| 469 panel_->manager()->Drag(delta_x, delta_y); | 469 panel_->manager()->Drag(mouse_location_); |
| 470 return true; | 470 return true; |
| 471 } | 471 } |
| 472 | 472 |
| 473 bool PanelBrowserView::OnTitlebarMouseReleased() { | 473 bool PanelBrowserView::OnTitlebarMouseReleased() { |
| 474 if (mouse_dragging_state_ == DRAGGING_STARTED) { | 474 if (mouse_dragging_state_ == DRAGGING_STARTED) { |
| 475 // When a drag ends, restore the focus. | 475 // When a drag ends, restore the focus. |
| 476 if (old_focused_view_) { | 476 if (old_focused_view_) { |
| 477 GetFocusManager()->SetFocusedView(old_focused_view_); | 477 GetFocusManager()->SetFocusedView(old_focused_view_); |
| 478 old_focused_view_ = NULL; | 478 old_focused_view_ = NULL; |
| 479 } | 479 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 if (!mouse_pressed_) | 521 if (!mouse_pressed_) |
| 522 return false; | 522 return false; |
| 523 mouse_pressed_ = false; | 523 mouse_pressed_ = false; |
| 524 | 524 |
| 525 mouse_dragging_state_ = DRAGGING_ENDED; | 525 mouse_dragging_state_ = DRAGGING_ENDED; |
| 526 panel_->manager()->EndDragging(cancelled); | 526 panel_->manager()->EndDragging(cancelled); |
| 527 return true; | 527 return true; |
| 528 } | 528 } |
| 529 | 529 |
| 530 void PanelBrowserView::SetPanelAppIconVisibility(bool visible) { | 530 void PanelBrowserView::SetPanelAppIconVisibility(bool visible) { |
| 531 // The panel should not show app icon in the desktop bar if it is in overflow. |
| 531 #if defined(OS_WIN) && !defined(USE_AURA) | 532 #if defined(OS_WIN) && !defined(USE_AURA) |
| 532 gfx::NativeWindow native_window = GetNativeHandle(); | 533 gfx::NativeWindow native_window = GetNativeHandle(); |
| 533 ::ShowWindow(native_window, SW_HIDE); | |
| 534 int style = ::GetWindowLong(native_window, GWL_EXSTYLE); | 534 int style = ::GetWindowLong(native_window, GWL_EXSTYLE); |
| 535 int new_style = style; |
| 535 if (visible) | 536 if (visible) |
| 536 style &= (~WS_EX_TOOLWINDOW); | 537 new_style &= (~WS_EX_TOOLWINDOW); |
| 537 else | 538 else |
| 538 style |= WS_EX_TOOLWINDOW; | 539 new_style |= WS_EX_TOOLWINDOW; |
| 539 ::SetWindowLong(native_window, GWL_EXSTYLE, style); | 540 if (style != new_style) { |
| 540 ::ShowWindow(native_window, SW_SHOWNA); | 541 ::ShowWindow(native_window, SW_HIDE); |
| 542 ::SetWindowLong(native_window, GWL_EXSTYLE, new_style); |
| 543 ::ShowWindow(native_window, SW_SHOWNA); |
| 544 } |
| 541 #else | 545 #else |
| 542 NOTIMPLEMENTED(); | 546 NOTIMPLEMENTED(); |
| 543 #endif | 547 #endif |
| 544 } | 548 } |
| 545 | 549 |
| 550 void PanelBrowserView::SetPanelAlwaysOnTop(bool on_top) { |
| 551 GetWidget()->SetAlwaysOnTop(on_top); |
| 552 } |
| 553 |
| 546 // NativePanelTesting implementation. | 554 // NativePanelTesting implementation. |
| 547 class NativePanelTestingWin : public NativePanelTesting { | 555 class NativePanelTestingWin : public NativePanelTesting { |
| 548 public: | 556 public: |
| 549 explicit NativePanelTestingWin(PanelBrowserView* panel_browser_view); | 557 explicit NativePanelTestingWin(PanelBrowserView* panel_browser_view); |
| 550 | 558 |
| 551 private: | 559 private: |
| 552 virtual void PressLeftMouseButtonTitlebar( | 560 virtual void PressLeftMouseButtonTitlebar( |
| 553 const gfx::Point& point) OVERRIDE; | 561 const gfx::Point& mouse_location) OVERRIDE; |
| 554 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; | 562 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; |
| 555 virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE; | 563 virtual void DragTitlebar(const gfx::Point& mouse_location) OVERRIDE; |
| 556 virtual void CancelDragTitlebar() OVERRIDE; | 564 virtual void CancelDragTitlebar() OVERRIDE; |
| 557 virtual void FinishDragTitlebar() OVERRIDE; | 565 virtual void FinishDragTitlebar() OVERRIDE; |
| 558 virtual bool VerifyDrawingAttention() const OVERRIDE; | 566 virtual bool VerifyDrawingAttention() const OVERRIDE; |
| 559 virtual bool VerifyActiveState(bool is_active) OVERRIDE; | 567 virtual bool VerifyActiveState(bool is_active) OVERRIDE; |
| 560 virtual bool IsWindowSizeKnown() const OVERRIDE; | 568 virtual bool IsWindowSizeKnown() const OVERRIDE; |
| 561 virtual bool IsAnimatingBounds() const OVERRIDE; | 569 virtual bool IsAnimatingBounds() const OVERRIDE; |
| 562 | 570 |
| 563 PanelBrowserView* panel_browser_view_; | 571 PanelBrowserView* panel_browser_view_; |
| 564 }; | 572 }; |
| 565 | 573 |
| 566 // static | 574 // static |
| 567 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { | 575 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { |
| 568 return new NativePanelTestingWin(static_cast<PanelBrowserView*>( | 576 return new NativePanelTestingWin(static_cast<PanelBrowserView*>( |
| 569 native_panel)); | 577 native_panel)); |
| 570 } | 578 } |
| 571 | 579 |
| 572 NativePanelTestingWin::NativePanelTestingWin( | 580 NativePanelTestingWin::NativePanelTestingWin( |
| 573 PanelBrowserView* panel_browser_view) : | 581 PanelBrowserView* panel_browser_view) : |
| 574 panel_browser_view_(panel_browser_view) { | 582 panel_browser_view_(panel_browser_view) { |
| 575 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); | 583 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); |
| 576 frame_view->title_label_->SetAutoColorReadabilityEnabled(false); | 584 frame_view->title_label_->SetAutoColorReadabilityEnabled(false); |
| 577 } | 585 } |
| 578 | 586 |
| 579 void NativePanelTestingWin::PressLeftMouseButtonTitlebar( | 587 void NativePanelTestingWin::PressLeftMouseButtonTitlebar( |
| 580 const gfx::Point& point) { | 588 const gfx::Point& mouse_location) { |
| 581 panel_browser_view_->OnTitlebarMousePressed(point); | 589 // Convert from the screen coordinate system to the view's coordinate system |
| 590 // since OnTitlebarMouseDragged takes the point in the latter. |
| 591 gfx::Point mouse_location_in_screen_coordinates = mouse_location; |
| 592 views::View::ConvertPointToView(NULL, panel_browser_view_, |
| 593 &mouse_location_in_screen_coordinates); |
| 594 panel_browser_view_->OnTitlebarMousePressed( |
| 595 mouse_location_in_screen_coordinates); |
| 582 } | 596 } |
| 583 | 597 |
| 584 void NativePanelTestingWin::ReleaseMouseButtonTitlebar() { | 598 void NativePanelTestingWin::ReleaseMouseButtonTitlebar() { |
| 585 panel_browser_view_->OnTitlebarMouseReleased(); | 599 panel_browser_view_->OnTitlebarMouseReleased(); |
| 586 } | 600 } |
| 587 | 601 |
| 588 void NativePanelTestingWin::DragTitlebar(int delta_x, int delta_y) { | 602 void NativePanelTestingWin::DragTitlebar(const gfx::Point& mouse_location) { |
| 589 gfx::Point new_mouse_location = panel_browser_view_->mouse_location_; | |
| 590 new_mouse_location.Offset(delta_x, delta_y); | |
| 591 | |
| 592 // Convert from the screen coordinate system to the view's coordinate system | 603 // Convert from the screen coordinate system to the view's coordinate system |
| 593 // since OnTitlebarMouseDragged takes the point in the latter. | 604 // since OnTitlebarMouseDragged takes the point in the latter. |
| 605 gfx::Point mouse_location_in_screen_coordinates = mouse_location; |
| 594 views::View::ConvertPointToView(NULL, panel_browser_view_, | 606 views::View::ConvertPointToView(NULL, panel_browser_view_, |
| 595 &new_mouse_location); | 607 &mouse_location_in_screen_coordinates); |
| 596 panel_browser_view_->OnTitlebarMouseDragged(new_mouse_location); | 608 panel_browser_view_->OnTitlebarMouseDragged( |
| 609 mouse_location_in_screen_coordinates); |
| 597 } | 610 } |
| 598 | 611 |
| 599 void NativePanelTestingWin::CancelDragTitlebar() { | 612 void NativePanelTestingWin::CancelDragTitlebar() { |
| 600 panel_browser_view_->OnTitlebarMouseCaptureLost(); | 613 panel_browser_view_->OnTitlebarMouseCaptureLost(); |
| 601 } | 614 } |
| 602 | 615 |
| 603 void NativePanelTestingWin::FinishDragTitlebar() { | 616 void NativePanelTestingWin::FinishDragTitlebar() { |
| 604 panel_browser_view_->OnTitlebarMouseReleased(); | 617 panel_browser_view_->OnTitlebarMouseReleased(); |
| 605 } | 618 } |
| 606 | 619 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 625 } | 638 } |
| 626 | 639 |
| 627 bool NativePanelTestingWin::IsWindowSizeKnown() const { | 640 bool NativePanelTestingWin::IsWindowSizeKnown() const { |
| 628 return true; | 641 return true; |
| 629 } | 642 } |
| 630 | 643 |
| 631 bool NativePanelTestingWin::IsAnimatingBounds() const { | 644 bool NativePanelTestingWin::IsAnimatingBounds() const { |
| 632 return panel_browser_view_->bounds_animator_.get() && | 645 return panel_browser_view_->bounds_animator_.get() && |
| 633 panel_browser_view_->bounds_animator_->is_animating(); | 646 panel_browser_view_->bounds_animator_->is_animating(); |
| 634 } | 647 } |
| OLD | NEW |