| 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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); | 420 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); |
| 421 #else | 421 #else |
| 422 NOTIMPLEMENTED(); | 422 NOTIMPLEMENTED(); |
| 423 #endif | 423 #endif |
| 424 } | 424 } |
| 425 | 425 |
| 426 PanelBrowserFrameView* PanelBrowserView::GetFrameView() const { | 426 PanelBrowserFrameView* PanelBrowserView::GetFrameView() const { |
| 427 return static_cast<PanelBrowserFrameView*>(frame()->GetFrameView()); | 427 return static_cast<PanelBrowserFrameView*>(frame()->GetFrameView()); |
| 428 } | 428 } |
| 429 | 429 |
| 430 bool PanelBrowserView::OnTitlebarMousePressed(const gfx::Point& location) { | 430 bool PanelBrowserView::OnTitlebarMousePressed( |
| 431 // |location| is in the view's coordinate system. Convert it to the screen | 431 const gfx::Point& mouse_location) { |
| 432 // coordinate system. | |
| 433 mouse_location_ = location; | |
| 434 views::View::ConvertPointToScreen(this, &mouse_location_); | |
| 435 | |
| 436 mouse_pressed_ = true; | 432 mouse_pressed_ = true; |
| 437 mouse_pressed_time_ = base::TimeTicks::Now(); | 433 mouse_pressed_time_ = base::TimeTicks::Now(); |
| 438 mouse_dragging_state_ = NO_DRAGGING; | 434 mouse_dragging_state_ = NO_DRAGGING; |
| 435 mouse_location_ = mouse_location; |
| 439 return true; | 436 return true; |
| 440 } | 437 } |
| 441 | 438 |
| 442 bool PanelBrowserView::OnTitlebarMouseDragged(const gfx::Point& location) { | 439 bool PanelBrowserView::OnTitlebarMouseDragged( |
| 440 const gfx::Point& mouse_location) { |
| 443 if (!mouse_pressed_) | 441 if (!mouse_pressed_) |
| 444 return false; | 442 return false; |
| 445 | 443 |
| 446 if (!panel_->draggable()) | 444 if (!panel_->draggable()) |
| 447 return true; | 445 return true; |
| 448 | 446 |
| 449 gfx::Point last_mouse_location = mouse_location_; | 447 gfx::Point last_mouse_location = mouse_location_; |
| 450 | 448 mouse_location_ = mouse_location; |
| 451 // |location| is in the view's coordinate system. Convert it to the screen | |
| 452 // coordinate system. | |
| 453 mouse_location_ = location; | |
| 454 views::View::ConvertPointToScreen(this, &mouse_location_); | |
| 455 | 449 |
| 456 int delta_x = mouse_location_.x() - last_mouse_location.x(); | 450 int delta_x = mouse_location_.x() - last_mouse_location.x(); |
| 457 int delta_y = mouse_location_.y() - last_mouse_location.y(); | 451 int delta_y = mouse_location_.y() - last_mouse_location.y(); |
| 458 if (mouse_dragging_state_ == NO_DRAGGING && | 452 if (mouse_dragging_state_ == NO_DRAGGING && |
| 459 ExceededDragThreshold(delta_x, delta_y)) { | 453 ExceededDragThreshold(delta_x, delta_y)) { |
| 460 // When a drag begins, we do not want to the client area to still receive | 454 // When a drag begins, we do not want to the client area to still receive |
| 461 // the focus. | 455 // the focus. |
| 462 old_focused_view_ = GetFocusManager()->GetFocusedView(); | 456 old_focused_view_ = GetFocusManager()->GetFocusedView(); |
| 463 GetFocusManager()->SetFocusedView(GetFrameView()); | 457 GetFocusManager()->SetFocusedView(GetFrameView()); |
| 464 | 458 |
| 465 panel_->manager()->StartDragging(panel_.get()); | 459 panel_->manager()->StartDragging(panel_.get(), last_mouse_location); |
| 466 mouse_dragging_state_ = DRAGGING_STARTED; | 460 mouse_dragging_state_ = DRAGGING_STARTED; |
| 467 } | 461 } |
| 468 if (mouse_dragging_state_ == DRAGGING_STARTED) | 462 if (mouse_dragging_state_ == DRAGGING_STARTED) |
| 469 panel_->manager()->Drag(delta_x, delta_y); | 463 panel_->manager()->Drag(mouse_location_); |
| 470 return true; | 464 return true; |
| 471 } | 465 } |
| 472 | 466 |
| 473 bool PanelBrowserView::OnTitlebarMouseReleased() { | 467 bool PanelBrowserView::OnTitlebarMouseReleased() { |
| 474 if (mouse_dragging_state_ == DRAGGING_STARTED) { | 468 if (mouse_dragging_state_ == DRAGGING_STARTED) { |
| 475 // When a drag ends, restore the focus. | 469 // When a drag ends, restore the focus. |
| 476 if (old_focused_view_) { | 470 if (old_focused_view_) { |
| 477 GetFocusManager()->SetFocusedView(old_focused_view_); | 471 GetFocusManager()->SetFocusedView(old_focused_view_); |
| 478 old_focused_view_ = NULL; | 472 old_focused_view_ = NULL; |
| 479 } | 473 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 #endif | 537 #endif |
| 544 } | 538 } |
| 545 | 539 |
| 546 // NativePanelTesting implementation. | 540 // NativePanelTesting implementation. |
| 547 class NativePanelTestingWin : public NativePanelTesting { | 541 class NativePanelTestingWin : public NativePanelTesting { |
| 548 public: | 542 public: |
| 549 explicit NativePanelTestingWin(PanelBrowserView* panel_browser_view); | 543 explicit NativePanelTestingWin(PanelBrowserView* panel_browser_view); |
| 550 | 544 |
| 551 private: | 545 private: |
| 552 virtual void PressLeftMouseButtonTitlebar( | 546 virtual void PressLeftMouseButtonTitlebar( |
| 553 const gfx::Point& point) OVERRIDE; | 547 const gfx::Point& mouse_location) OVERRIDE; |
| 554 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; | 548 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; |
| 555 virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE; | 549 virtual void DragTitlebar(const gfx::Point& mouse_location) OVERRIDE; |
| 556 virtual void CancelDragTitlebar() OVERRIDE; | 550 virtual void CancelDragTitlebar() OVERRIDE; |
| 557 virtual void FinishDragTitlebar() OVERRIDE; | 551 virtual void FinishDragTitlebar() OVERRIDE; |
| 558 virtual bool VerifyDrawingAttention() const OVERRIDE; | 552 virtual bool VerifyDrawingAttention() const OVERRIDE; |
| 559 virtual bool VerifyActiveState(bool is_active) OVERRIDE; | 553 virtual bool VerifyActiveState(bool is_active) OVERRIDE; |
| 560 virtual bool IsWindowSizeKnown() const OVERRIDE; | 554 virtual bool IsWindowSizeKnown() const OVERRIDE; |
| 561 virtual bool IsAnimatingBounds() const OVERRIDE; | 555 virtual bool IsAnimatingBounds() const OVERRIDE; |
| 562 | 556 |
| 563 PanelBrowserView* panel_browser_view_; | 557 PanelBrowserView* panel_browser_view_; |
| 564 }; | 558 }; |
| 565 | 559 |
| 566 // static | 560 // static |
| 567 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { | 561 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { |
| 568 return new NativePanelTestingWin(static_cast<PanelBrowserView*>( | 562 return new NativePanelTestingWin(static_cast<PanelBrowserView*>( |
| 569 native_panel)); | 563 native_panel)); |
| 570 } | 564 } |
| 571 | 565 |
| 572 NativePanelTestingWin::NativePanelTestingWin( | 566 NativePanelTestingWin::NativePanelTestingWin( |
| 573 PanelBrowserView* panel_browser_view) : | 567 PanelBrowserView* panel_browser_view) : |
| 574 panel_browser_view_(panel_browser_view) { | 568 panel_browser_view_(panel_browser_view) { |
| 575 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); | 569 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); |
| 576 frame_view->title_label_->SetAutoColorReadabilityEnabled(false); | 570 frame_view->title_label_->SetAutoColorReadabilityEnabled(false); |
| 577 } | 571 } |
| 578 | 572 |
| 579 void NativePanelTestingWin::PressLeftMouseButtonTitlebar( | 573 void NativePanelTestingWin::PressLeftMouseButtonTitlebar( |
| 580 const gfx::Point& point) { | 574 const gfx::Point& mouse_location) { |
| 581 panel_browser_view_->OnTitlebarMousePressed(point); | 575 panel_browser_view_->OnTitlebarMousePressed(mouse_location); |
| 582 } | 576 } |
| 583 | 577 |
| 584 void NativePanelTestingWin::ReleaseMouseButtonTitlebar() { | 578 void NativePanelTestingWin::ReleaseMouseButtonTitlebar() { |
| 585 panel_browser_view_->OnTitlebarMouseReleased(); | 579 panel_browser_view_->OnTitlebarMouseReleased(); |
| 586 } | 580 } |
| 587 | 581 |
| 588 void NativePanelTestingWin::DragTitlebar(int delta_x, int delta_y) { | 582 void NativePanelTestingWin::DragTitlebar(const gfx::Point& mouse_location) { |
| 589 gfx::Point new_mouse_location = panel_browser_view_->mouse_location_; | 583 panel_browser_view_->OnTitlebarMouseDragged(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 | |
| 593 // since OnTitlebarMouseDragged takes the point in the latter. | |
| 594 views::View::ConvertPointToView(NULL, panel_browser_view_, | |
| 595 &new_mouse_location); | |
| 596 panel_browser_view_->OnTitlebarMouseDragged(new_mouse_location); | |
| 597 } | 584 } |
| 598 | 585 |
| 599 void NativePanelTestingWin::CancelDragTitlebar() { | 586 void NativePanelTestingWin::CancelDragTitlebar() { |
| 600 panel_browser_view_->OnTitlebarMouseCaptureLost(); | 587 panel_browser_view_->OnTitlebarMouseCaptureLost(); |
| 601 } | 588 } |
| 602 | 589 |
| 603 void NativePanelTestingWin::FinishDragTitlebar() { | 590 void NativePanelTestingWin::FinishDragTitlebar() { |
| 604 panel_browser_view_->OnTitlebarMouseReleased(); | 591 panel_browser_view_->OnTitlebarMouseReleased(); |
| 605 } | 592 } |
| 606 | 593 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 625 } | 612 } |
| 626 | 613 |
| 627 bool NativePanelTestingWin::IsWindowSizeKnown() const { | 614 bool NativePanelTestingWin::IsWindowSizeKnown() const { |
| 628 return true; | 615 return true; |
| 629 } | 616 } |
| 630 | 617 |
| 631 bool NativePanelTestingWin::IsAnimatingBounds() const { | 618 bool NativePanelTestingWin::IsAnimatingBounds() const { |
| 632 return panel_browser_view_->bounds_animator_.get() && | 619 return panel_browser_view_->bounds_animator_.get() && |
| 633 panel_browser_view_->bounds_animator_->is_animating(); | 620 panel_browser_view_->bounds_animator_->is_animating(); |
| 634 } | 621 } |
| OLD | NEW |