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