| 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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(const gfx::Point& location) { |
| 431 // |location| is in the view's coordinate system. Convert it to the screen | |
| 432 // coordinate system. | |
| 433 mouse_location_ = location; | |
| 434 views::View::ConvertPointToScreen(this, &mouse_location_); | |
| 435 | |
| 436 mouse_pressed_ = true; | 431 mouse_pressed_ = true; |
| 437 mouse_pressed_time_ = base::TimeTicks::Now(); | 432 mouse_pressed_time_ = base::TimeTicks::Now(); |
| 438 mouse_dragging_state_ = NO_DRAGGING; | 433 mouse_dragging_state_ = NO_DRAGGING; |
| 434 mouse_location_ = location; |
| 439 return true; | 435 return true; |
| 440 } | 436 } |
| 441 | 437 |
| 442 bool PanelBrowserView::OnTitlebarMouseDragged(const gfx::Point& location) { | 438 bool PanelBrowserView::OnTitlebarMouseDragged(const gfx::Point& location) { |
| 443 if (!mouse_pressed_) | 439 if (!mouse_pressed_) |
| 444 return false; | 440 return false; |
| 445 | 441 |
| 446 if (!panel_->draggable()) | 442 if (!panel_->draggable()) |
| 447 return true; | 443 return true; |
| 448 | 444 |
| 449 gfx::Point last_mouse_location = mouse_location_; | 445 gfx::Point last_mouse_location = mouse_location_; |
| 450 | |
| 451 // |location| is in the view's coordinate system. Convert it to the screen | |
| 452 // coordinate system. | |
| 453 mouse_location_ = location; | 446 mouse_location_ = location; |
| 454 views::View::ConvertPointToScreen(this, &mouse_location_); | |
| 455 | 447 |
| 456 int delta_x = mouse_location_.x() - last_mouse_location.x(); | 448 int delta_x = mouse_location_.x() - last_mouse_location.x(); |
| 457 int delta_y = mouse_location_.y() - last_mouse_location.y(); | 449 int delta_y = mouse_location_.y() - last_mouse_location.y(); |
| 458 if (mouse_dragging_state_ == NO_DRAGGING && | 450 if (mouse_dragging_state_ == NO_DRAGGING && |
| 459 ExceededDragThreshold(delta_x, delta_y)) { | 451 ExceededDragThreshold(delta_x, delta_y)) { |
| 460 // When a drag begins, we do not want to the client area to still receive | 452 // When a drag begins, we do not want to the client area to still receive |
| 461 // the focus. | 453 // the focus. |
| 462 old_focused_view_ = GetFocusManager()->GetFocusedView(); | 454 old_focused_view_ = GetFocusManager()->GetFocusedView(); |
| 463 GetFocusManager()->SetFocusedView(GetFrameView()); | 455 GetFocusManager()->SetFocusedView(GetFrameView()); |
| 464 | 456 |
| 465 panel_->manager()->StartDragging(panel_.get()); | 457 panel_->manager()->StartDragging(panel_.get(), last_mouse_location); |
| 466 mouse_dragging_state_ = DRAGGING_STARTED; | 458 mouse_dragging_state_ = DRAGGING_STARTED; |
| 467 } | 459 } |
| 468 if (mouse_dragging_state_ == DRAGGING_STARTED) | 460 if (mouse_dragging_state_ == DRAGGING_STARTED) |
| 469 panel_->manager()->Drag(delta_x, delta_y); | 461 panel_->manager()->Drag(mouse_location_); |
| 470 return true; | 462 return true; |
| 471 } | 463 } |
| 472 | 464 |
| 473 bool PanelBrowserView::OnTitlebarMouseReleased() { | 465 bool PanelBrowserView::OnTitlebarMouseReleased() { |
| 474 if (mouse_dragging_state_ == DRAGGING_STARTED) { | 466 if (mouse_dragging_state_ == DRAGGING_STARTED) { |
| 475 // When a drag ends, restore the focus. | 467 // When a drag ends, restore the focus. |
| 476 if (old_focused_view_) { | 468 if (old_focused_view_) { |
| 477 GetFocusManager()->SetFocusedView(old_focused_view_); | 469 GetFocusManager()->SetFocusedView(old_focused_view_); |
| 478 old_focused_view_ = NULL; | 470 old_focused_view_ = NULL; |
| 479 } | 471 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 if (!mouse_pressed_) | 513 if (!mouse_pressed_) |
| 522 return false; | 514 return false; |
| 523 mouse_pressed_ = false; | 515 mouse_pressed_ = false; |
| 524 | 516 |
| 525 mouse_dragging_state_ = DRAGGING_ENDED; | 517 mouse_dragging_state_ = DRAGGING_ENDED; |
| 526 panel_->manager()->EndDragging(cancelled); | 518 panel_->manager()->EndDragging(cancelled); |
| 527 return true; | 519 return true; |
| 528 } | 520 } |
| 529 | 521 |
| 530 void PanelBrowserView::SetPanelAppIconVisibility(bool visible) { | 522 void PanelBrowserView::SetPanelAppIconVisibility(bool visible) { |
| 523 // The panel should not show app icon in the desktop bar if it is in overflow. |
| 531 #if defined(OS_WIN) && !defined(USE_AURA) | 524 #if defined(OS_WIN) && !defined(USE_AURA) |
| 532 gfx::NativeWindow native_window = GetNativeHandle(); | 525 gfx::NativeWindow native_window = GetNativeHandle(); |
| 533 ::ShowWindow(native_window, SW_HIDE); | |
| 534 int style = ::GetWindowLong(native_window, GWL_EXSTYLE); | 526 int style = ::GetWindowLong(native_window, GWL_EXSTYLE); |
| 527 int new_style = style; |
| 535 if (visible) | 528 if (visible) |
| 536 style &= (~WS_EX_TOOLWINDOW); | 529 new_style &= (~WS_EX_TOOLWINDOW); |
| 537 else | 530 else |
| 538 style |= WS_EX_TOOLWINDOW; | 531 new_style |= WS_EX_TOOLWINDOW; |
| 539 ::SetWindowLong(native_window, GWL_EXSTYLE, style); | 532 if (style != new_style) { |
| 540 ::ShowWindow(native_window, SW_SHOWNA); | 533 ::ShowWindow(native_window, SW_HIDE); |
| 534 ::SetWindowLong(native_window, GWL_EXSTYLE, new_style); |
| 535 ::ShowWindow(native_window, SW_SHOWNA); |
| 536 } |
| 541 #else | 537 #else |
| 542 NOTIMPLEMENTED(); | 538 NOTIMPLEMENTED(); |
| 543 #endif | 539 #endif |
| 544 } | 540 } |
| 545 | 541 |
| 542 void PanelBrowserView::SetPanelAlwaysOnTop(bool on_top) { |
| 543 GetWidget()->SetAlwaysOnTop(on_top); |
| 544 } |
| 545 |
| 546 // NativePanelTesting implementation. | 546 // NativePanelTesting implementation. |
| 547 class NativePanelTestingWin : public NativePanelTesting { | 547 class NativePanelTestingWin : public NativePanelTesting { |
| 548 public: | 548 public: |
| 549 explicit NativePanelTestingWin(PanelBrowserView* panel_browser_view); | 549 explicit NativePanelTestingWin(PanelBrowserView* panel_browser_view); |
| 550 | 550 |
| 551 private: | 551 private: |
| 552 virtual void PressLeftMouseButtonTitlebar( | 552 virtual void PressLeftMouseButtonTitlebar( |
| 553 const gfx::Point& point) OVERRIDE; | 553 const gfx::Point& mouse_location) OVERRIDE; |
| 554 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; | 554 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; |
| 555 virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE; | 555 virtual void DragTitlebar(const gfx::Point& mouse_location) OVERRIDE; |
| 556 virtual void CancelDragTitlebar() OVERRIDE; | 556 virtual void CancelDragTitlebar() OVERRIDE; |
| 557 virtual void FinishDragTitlebar() OVERRIDE; | 557 virtual void FinishDragTitlebar() OVERRIDE; |
| 558 virtual bool VerifyDrawingAttention() const OVERRIDE; | 558 virtual bool VerifyDrawingAttention() const OVERRIDE; |
| 559 virtual bool VerifyActiveState(bool is_active) OVERRIDE; | 559 virtual bool VerifyActiveState(bool is_active) OVERRIDE; |
| 560 virtual bool IsWindowSizeKnown() const OVERRIDE; | 560 virtual bool IsWindowSizeKnown() const OVERRIDE; |
| 561 virtual bool IsAnimatingBounds() const OVERRIDE; | 561 virtual bool IsAnimatingBounds() const OVERRIDE; |
| 562 | 562 |
| 563 PanelBrowserView* panel_browser_view_; | 563 PanelBrowserView* panel_browser_view_; |
| 564 }; | 564 }; |
| 565 | 565 |
| 566 // static | 566 // static |
| 567 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { | 567 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { |
| 568 return new NativePanelTestingWin(static_cast<PanelBrowserView*>( | 568 return new NativePanelTestingWin(static_cast<PanelBrowserView*>( |
| 569 native_panel)); | 569 native_panel)); |
| 570 } | 570 } |
| 571 | 571 |
| 572 NativePanelTestingWin::NativePanelTestingWin( | 572 NativePanelTestingWin::NativePanelTestingWin( |
| 573 PanelBrowserView* panel_browser_view) : | 573 PanelBrowserView* panel_browser_view) : |
| 574 panel_browser_view_(panel_browser_view) { | 574 panel_browser_view_(panel_browser_view) { |
| 575 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); | 575 PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); |
| 576 frame_view->title_label_->SetAutoColorReadabilityEnabled(false); | 576 frame_view->title_label_->SetAutoColorReadabilityEnabled(false); |
| 577 } | 577 } |
| 578 | 578 |
| 579 void NativePanelTestingWin::PressLeftMouseButtonTitlebar( | 579 void NativePanelTestingWin::PressLeftMouseButtonTitlebar( |
| 580 const gfx::Point& point) { | 580 const gfx::Point& mouse_location) { |
| 581 panel_browser_view_->OnTitlebarMousePressed(point); | 581 panel_browser_view_->OnTitlebarMousePressed(mouse_location); |
| 582 } | 582 } |
| 583 | 583 |
| 584 void NativePanelTestingWin::ReleaseMouseButtonTitlebar() { | 584 void NativePanelTestingWin::ReleaseMouseButtonTitlebar() { |
| 585 panel_browser_view_->OnTitlebarMouseReleased(); | 585 panel_browser_view_->OnTitlebarMouseReleased(); |
| 586 } | 586 } |
| 587 | 587 |
| 588 void NativePanelTestingWin::DragTitlebar(int delta_x, int delta_y) { | 588 void NativePanelTestingWin::DragTitlebar(const gfx::Point& mouse_location) { |
| 589 gfx::Point new_mouse_location = panel_browser_view_->mouse_location_; | 589 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 } | 590 } |
| 598 | 591 |
| 599 void NativePanelTestingWin::CancelDragTitlebar() { | 592 void NativePanelTestingWin::CancelDragTitlebar() { |
| 600 panel_browser_view_->OnTitlebarMouseCaptureLost(); | 593 panel_browser_view_->OnTitlebarMouseCaptureLost(); |
| 601 } | 594 } |
| 602 | 595 |
| 603 void NativePanelTestingWin::FinishDragTitlebar() { | 596 void NativePanelTestingWin::FinishDragTitlebar() { |
| 604 panel_browser_view_->OnTitlebarMouseReleased(); | 597 panel_browser_view_->OnTitlebarMouseReleased(); |
| 605 } | 598 } |
| 606 | 599 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 625 } | 618 } |
| 626 | 619 |
| 627 bool NativePanelTestingWin::IsWindowSizeKnown() const { | 620 bool NativePanelTestingWin::IsWindowSizeKnown() const { |
| 628 return true; | 621 return true; |
| 629 } | 622 } |
| 630 | 623 |
| 631 bool NativePanelTestingWin::IsAnimatingBounds() const { | 624 bool NativePanelTestingWin::IsAnimatingBounds() const { |
| 632 return panel_browser_view_->bounds_animator_.get() && | 625 return panel_browser_view_->bounds_animator_.get() && |
| 633 panel_browser_view_->bounds_animator_->is_animating(); | 626 panel_browser_view_->bounds_animator_->is_animating(); |
| 634 } | 627 } |
| OLD | NEW |