| 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_window_gtk.h" | 5 #include "chrome/browser/ui/panels/panel_browser_window_gtk.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/ui/browser_list.h" | 8 #include "chrome/browser/ui/browser_list.h" |
| 9 #include "chrome/browser/ui/gtk/browser_titlebar.h" | 9 #include "chrome/browser/ui/gtk/browser_titlebar.h" |
| 10 #include "chrome/browser/ui/panels/panel.h" | 10 #include "chrome/browser/ui/panels/panel.h" |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 } | 475 } |
| 476 | 476 |
| 477 void PanelBrowserWindowGtk::EnsurePanelFullyVisible() { | 477 void PanelBrowserWindowGtk::EnsurePanelFullyVisible() { |
| 478 gtk_window_present(window()); | 478 gtk_window_present(window()); |
| 479 } | 479 } |
| 480 | 480 |
| 481 void PanelBrowserWindowGtk::SetPanelAppIconVisibility(bool visible) { | 481 void PanelBrowserWindowGtk::SetPanelAppIconVisibility(bool visible) { |
| 482 return; | 482 return; |
| 483 } | 483 } |
| 484 | 484 |
| 485 void PanelBrowserWindowGtk::SetPanelAlwaysOnTop(bool on_top) { |
| 486 gtk_window_set_keep_above(window(), on_top); |
| 487 } |
| 488 |
| 485 gfx::Size PanelBrowserWindowGtk::WindowSizeFromContentSize( | 489 gfx::Size PanelBrowserWindowGtk::WindowSizeFromContentSize( |
| 486 const gfx::Size& content_size) const { | 490 const gfx::Size& content_size) const { |
| 487 gfx::Size frame = GetNonClientFrameSize(); | 491 gfx::Size frame = GetNonClientFrameSize(); |
| 488 return gfx::Size(content_size.width() + frame.width(), | 492 return gfx::Size(content_size.width() + frame.width(), |
| 489 content_size.height() + frame.height()); | 493 content_size.height() + frame.height()); |
| 490 } | 494 } |
| 491 | 495 |
| 492 gfx::Size PanelBrowserWindowGtk::ContentSizeFromWindowSize( | 496 gfx::Size PanelBrowserWindowGtk::ContentSizeFromWindowSize( |
| 493 const gfx::Size& window_size) const { | 497 const gfx::Size& window_size) const { |
| 494 gfx::Size frame = GetNonClientFrameSize(); | 498 gfx::Size frame = GetNonClientFrameSize(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 gtk_drag_check_threshold(titlebar_widget(), old_x, | 548 gtk_drag_check_threshold(titlebar_widget(), old_x, |
| 545 old_y, new_x, new_y)) { | 549 old_y, new_x, new_y)) { |
| 546 CreateDragWidget(); | 550 CreateDragWidget(); |
| 547 if (!system_drag_disabled_for_testing_) { | 551 if (!system_drag_disabled_for_testing_) { |
| 548 GtkTargetList* list = ui::GetTargetListFromCodeMask(ui::CHROME_TAB); | 552 GtkTargetList* list = ui::GetTargetListFromCodeMask(ui::CHROME_TAB); |
| 549 gtk_drag_begin(drag_widget_, list, GDK_ACTION_MOVE, 1, last_mouse_down_); | 553 gtk_drag_begin(drag_widget_, list, GDK_ACTION_MOVE, 1, last_mouse_down_); |
| 550 // gtk_drag_begin increments reference count for GtkTargetList. So unref | 554 // gtk_drag_begin increments reference count for GtkTargetList. So unref |
| 551 // it here to reduce the reference count. | 555 // it here to reduce the reference count. |
| 552 gtk_target_list_unref(list); | 556 gtk_target_list_unref(list); |
| 553 } | 557 } |
| 554 panel_->manager()->StartDragging(panel_.get()); | 558 panel_->manager()->StartDragging(panel_.get(), gfx::Point(old_x, old_y)); |
| 555 } | 559 } |
| 556 | 560 |
| 557 if (drag_widget_) { | 561 if (drag_widget_) { |
| 558 panel_->manager()->Drag(new_x - old_x, new_y - old_y); | 562 panel_->manager()->Drag(gfx::Point(new_x, new_y)); |
| 559 gdk_event_free(last_mouse_down_); | 563 gdk_event_free(last_mouse_down_); |
| 560 last_mouse_down_ = gdk_event_copy(event); | 564 last_mouse_down_ = gdk_event_copy(event); |
| 561 } | 565 } |
| 562 } | 566 } |
| 563 | 567 |
| 564 void PanelBrowserWindowGtk::AnimationEnded(const ui::Animation* animation) { | 568 void PanelBrowserWindowGtk::AnimationEnded(const ui::Animation* animation) { |
| 565 titlebar()->SendEnterNotifyToCloseButtonIfUnderMouse(); | 569 titlebar()->SendEnterNotifyToCloseButtonIfUnderMouse(); |
| 566 | 570 |
| 567 // If the final size is 0 in either dimension, hide the window as gtk does | 571 // If the final size is 0 in either dimension, hide the window as gtk does |
| 568 // not allow the window size to be 0. | 572 // not allow the window size to be 0. |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 } | 774 } |
| 771 | 775 |
| 772 // NativePanelTesting implementation. | 776 // NativePanelTesting implementation. |
| 773 class NativePanelTestingGtk : public NativePanelTesting { | 777 class NativePanelTestingGtk : public NativePanelTesting { |
| 774 public: | 778 public: |
| 775 explicit NativePanelTestingGtk( | 779 explicit NativePanelTestingGtk( |
| 776 PanelBrowserWindowGtk* panel_browser_window_gtk); | 780 PanelBrowserWindowGtk* panel_browser_window_gtk); |
| 777 | 781 |
| 778 private: | 782 private: |
| 779 virtual void PressLeftMouseButtonTitlebar( | 783 virtual void PressLeftMouseButtonTitlebar( |
| 780 const gfx::Point& point) OVERRIDE; | 784 const gfx::Point& mouse_location) OVERRIDE; |
| 781 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; | 785 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; |
| 782 virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE; | 786 virtual void DragTitlebar(const gfx::Point& mouse_location) OVERRIDE; |
| 783 virtual void CancelDragTitlebar() OVERRIDE; | 787 virtual void CancelDragTitlebar() OVERRIDE; |
| 784 virtual void FinishDragTitlebar() OVERRIDE; | 788 virtual void FinishDragTitlebar() OVERRIDE; |
| 785 virtual bool VerifyDrawingAttention() const OVERRIDE; | 789 virtual bool VerifyDrawingAttention() const OVERRIDE; |
| 786 virtual bool VerifyActiveState(bool is_active) OVERRIDE; | 790 virtual bool VerifyActiveState(bool is_active) OVERRIDE; |
| 787 virtual void WaitForWindowCreationToComplete() const OVERRIDE; | 791 virtual void WaitForWindowCreationToComplete() const OVERRIDE; |
| 788 virtual bool IsWindowSizeKnown() const OVERRIDE; | 792 virtual bool IsWindowSizeKnown() const OVERRIDE; |
| 789 virtual bool IsAnimatingBounds() const OVERRIDE; | 793 virtual bool IsAnimatingBounds() const OVERRIDE; |
| 790 | 794 |
| 791 PanelBrowserWindowGtk* panel_browser_window_gtk_; | 795 PanelBrowserWindowGtk* panel_browser_window_gtk_; |
| 792 }; | 796 }; |
| 793 | 797 |
| 794 // static | 798 // static |
| 795 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { | 799 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { |
| 796 return new NativePanelTestingGtk(static_cast<PanelBrowserWindowGtk*>( | 800 return new NativePanelTestingGtk(static_cast<PanelBrowserWindowGtk*>( |
| 797 native_panel)); | 801 native_panel)); |
| 798 } | 802 } |
| 799 | 803 |
| 800 NativePanelTestingGtk::NativePanelTestingGtk( | 804 NativePanelTestingGtk::NativePanelTestingGtk( |
| 801 PanelBrowserWindowGtk* panel_browser_window_gtk) : | 805 PanelBrowserWindowGtk* panel_browser_window_gtk) : |
| 802 panel_browser_window_gtk_(panel_browser_window_gtk) { | 806 panel_browser_window_gtk_(panel_browser_window_gtk) { |
| 803 } | 807 } |
| 804 | 808 |
| 805 void NativePanelTestingGtk::PressLeftMouseButtonTitlebar( | 809 void NativePanelTestingGtk::PressLeftMouseButtonTitlebar( |
| 806 const gfx::Point& point) { | 810 const gfx::Point& mouse_location) { |
| 807 // If there is an animation, wait for it to finish as we don't handle button | 811 // If there is an animation, wait for it to finish as we don't handle button |
| 808 // clicks while animation is in progress. | 812 // clicks while animation is in progress. |
| 809 while (panel_browser_window_gtk_->IsAnimatingBounds()) | 813 while (panel_browser_window_gtk_->IsAnimatingBounds()) |
| 810 MessageLoopForUI::current()->RunAllPending(); | 814 MessageLoopForUI::current()->RunAllPending(); |
| 811 | 815 |
| 812 GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS); | 816 GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS); |
| 813 event->button.button = 1; | 817 event->button.button = 1; |
| 814 event->button.x_root = point.x(); | 818 event->button.x_root = mouse_location.x(); |
| 815 event->button.y_root = point.y(); | 819 event->button.y_root = mouse_location.y(); |
| 816 panel_browser_window_gtk_->OnTitlebarButtonPressEvent( | 820 panel_browser_window_gtk_->OnTitlebarButtonPressEvent( |
| 817 panel_browser_window_gtk_->titlebar_widget(), | 821 panel_browser_window_gtk_->titlebar_widget(), |
| 818 reinterpret_cast<GdkEventButton*>(event)); | 822 reinterpret_cast<GdkEventButton*>(event)); |
| 819 gdk_event_free(event); | 823 gdk_event_free(event); |
| 820 MessageLoopForUI::current()->RunAllPending(); | 824 MessageLoopForUI::current()->RunAllPending(); |
| 821 } | 825 } |
| 822 | 826 |
| 823 void NativePanelTestingGtk::ReleaseMouseButtonTitlebar() { | 827 void NativePanelTestingGtk::ReleaseMouseButtonTitlebar() { |
| 824 GdkEvent* event = gdk_event_new(GDK_BUTTON_RELEASE); | 828 GdkEvent* event = gdk_event_new(GDK_BUTTON_RELEASE); |
| 825 event->button.button = 1; | 829 event->button.button = 1; |
| 826 panel_browser_window_gtk_->OnTitlebarButtonReleaseEvent( | 830 panel_browser_window_gtk_->OnTitlebarButtonReleaseEvent( |
| 827 panel_browser_window_gtk_->titlebar_widget(), | 831 panel_browser_window_gtk_->titlebar_widget(), |
| 828 reinterpret_cast<GdkEventButton*>(event)); | 832 reinterpret_cast<GdkEventButton*>(event)); |
| 829 MessageLoopForUI::current()->RunAllPending(); | 833 MessageLoopForUI::current()->RunAllPending(); |
| 830 } | 834 } |
| 831 | 835 |
| 832 void NativePanelTestingGtk::DragTitlebar(int delta_x, int delta_y) { | 836 void NativePanelTestingGtk::DragTitlebar(const gfx::Point& mouse_location) { |
| 833 // Prevent extra unwanted signals and focus grabs. | 837 // Prevent extra unwanted signals and focus grabs. |
| 834 panel_browser_window_gtk_->system_drag_disabled_for_testing_ = true; | 838 panel_browser_window_gtk_->system_drag_disabled_for_testing_ = true; |
| 835 | 839 |
| 836 GdkEvent* event = gdk_event_new(GDK_MOTION_NOTIFY); | 840 GdkEvent* event = gdk_event_new(GDK_MOTION_NOTIFY); |
| 837 gdk_event_get_root_coords(panel_browser_window_gtk_->last_mouse_down_, | 841 event->motion.x_root = mouse_location.x(); |
| 838 &event->motion.x_root, &event->motion.y_root); | 842 event->motion.y_root = mouse_location.y(); |
| 839 event->motion.x_root += delta_x; | |
| 840 event->motion.y_root += delta_y; | |
| 841 panel_browser_window_gtk_->DidProcessEvent(event); | 843 panel_browser_window_gtk_->DidProcessEvent(event); |
| 842 gdk_event_free(event); | 844 gdk_event_free(event); |
| 843 MessageLoopForUI::current()->RunAllPending(); | 845 MessageLoopForUI::current()->RunAllPending(); |
| 844 } | 846 } |
| 845 | 847 |
| 846 void NativePanelTestingGtk::CancelDragTitlebar() { | 848 void NativePanelTestingGtk::CancelDragTitlebar() { |
| 847 panel_browser_window_gtk_->OnDragFailed( | 849 panel_browser_window_gtk_->OnDragFailed( |
| 848 panel_browser_window_gtk_->drag_widget_, NULL, | 850 panel_browser_window_gtk_->drag_widget_, NULL, |
| 849 GTK_DRAG_RESULT_USER_CANCELLED); | 851 GTK_DRAG_RESULT_USER_CANCELLED); |
| 850 MessageLoopForUI::current()->RunAllPending(); | 852 MessageLoopForUI::current()->RunAllPending(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 877 MessageLoopForUI::current()->RunAllPending(); | 879 MessageLoopForUI::current()->RunAllPending(); |
| 878 } | 880 } |
| 879 | 881 |
| 880 bool NativePanelTestingGtk::IsWindowSizeKnown() const { | 882 bool NativePanelTestingGtk::IsWindowSizeKnown() const { |
| 881 return panel_browser_window_gtk_->window_size_known_; | 883 return panel_browser_window_gtk_->window_size_known_; |
| 882 } | 884 } |
| 883 | 885 |
| 884 bool NativePanelTestingGtk::IsAnimatingBounds() const { | 886 bool NativePanelTestingGtk::IsAnimatingBounds() const { |
| 885 return panel_browser_window_gtk_->IsAnimatingBounds(); | 887 return panel_browser_window_gtk_->IsAnimatingBounds(); |
| 886 } | 888 } |
| OLD | NEW |