| 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" |
| 11 #include "chrome/browser/ui/panels/panel_bounds_animation.h" | 11 #include "chrome/browser/ui/panels/panel_bounds_animation.h" |
| 12 #include "chrome/browser/ui/panels/panel_drag_gtk.h" | 12 #include "chrome/browser/ui/panels/panel_drag_gtk.h" |
| 13 #include "chrome/browser/ui/panels/panel_manager.h" | 13 #include "chrome/browser/ui/panels/panel_manager.h" |
| 14 #include "chrome/browser/ui/panels/panel_strip.h" | 14 #include "chrome/browser/ui/panels/panel_strip.h" |
| 15 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" | |
| 16 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 18 #include "ui/base/dragdrop/gtk_dnd_util.h" | 17 #include "ui/base/dragdrop/gtk_dnd_util.h" |
| 19 | 18 |
| 20 using content::WebContents; | 19 using content::WebContents; |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 // RGB values for titlebar in draw attention state. A shade of orange. | 23 // RGB values for titlebar in draw attention state. A shade of orange. |
| 25 const int kDrawAttentionR = 0xfa; | 24 const int kDrawAttentionR = 0xfa; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 56 Panel* panel, | 55 Panel* panel, |
| 57 const gfx::Rect& bounds) | 56 const gfx::Rect& bounds) |
| 58 : BrowserWindowGtk(browser), | 57 : BrowserWindowGtk(browser), |
| 59 system_drag_disabled_for_testing_(false), | 58 system_drag_disabled_for_testing_(false), |
| 60 last_mouse_down_(NULL), | 59 last_mouse_down_(NULL), |
| 61 drag_widget_(NULL), | 60 drag_widget_(NULL), |
| 62 drag_end_factory_(this), | 61 drag_end_factory_(this), |
| 63 panel_(panel), | 62 panel_(panel), |
| 64 bounds_(bounds), | 63 bounds_(bounds), |
| 65 is_drawing_attention_(false), | 64 is_drawing_attention_(false), |
| 66 window_has_mouse_(false), | |
| 67 show_close_button_(true) { | 65 show_close_button_(true) { |
| 68 } | 66 } |
| 69 | 67 |
| 70 PanelBrowserWindowGtk::~PanelBrowserWindowGtk() { | 68 PanelBrowserWindowGtk::~PanelBrowserWindowGtk() { |
| 71 CleanupDragDrop(); | 69 CleanupDragDrop(); |
| 72 } | 70 } |
| 73 | 71 |
| 74 void PanelBrowserWindowGtk::Init() { | 72 void PanelBrowserWindowGtk::Init() { |
| 75 BrowserWindowGtk::Init(); | 73 BrowserWindowGtk::Init(); |
| 76 | 74 |
| 77 // Keep the window always on top. | 75 // Keep the window always on top. |
| 78 gtk_window_set_keep_above(window(), TRUE); | 76 gtk_window_set_keep_above(window(), TRUE); |
| 79 | 77 |
| 80 // Show the window on all the virtual desktops. | 78 // Show the window on all the virtual desktops. |
| 81 gtk_window_stick(window()); | 79 gtk_window_stick(window()); |
| 82 | 80 |
| 83 // Do not show an icon in the task bar. Window operations such as close, | 81 // Do not show an icon in the task bar. Window operations such as close, |
| 84 // minimize etc. can only be done from the panel UI. | 82 // minimize etc. can only be done from the panel UI. |
| 85 gtk_window_set_skip_taskbar_hint(window(), TRUE); | 83 gtk_window_set_skip_taskbar_hint(window(), TRUE); |
| 86 | 84 |
| 87 g_signal_connect(titlebar_widget(), "button-press-event", | 85 g_signal_connect(titlebar_widget(), "button-press-event", |
| 88 G_CALLBACK(OnTitlebarButtonPressEventThunk), this); | 86 G_CALLBACK(OnTitlebarButtonPressEventThunk), this); |
| 89 g_signal_connect(titlebar_widget(), "button-release-event", | 87 g_signal_connect(titlebar_widget(), "button-release-event", |
| 90 G_CALLBACK(OnTitlebarButtonReleaseEventThunk), this); | 88 G_CALLBACK(OnTitlebarButtonReleaseEventThunk), this); |
| 91 | 89 |
| 92 g_signal_connect(window_, "enter-notify-event", | |
| 93 G_CALLBACK(OnEnterNotifyThunk), this); | |
| 94 g_signal_connect(window_, "leave-notify-event", | |
| 95 G_CALLBACK(OnLeaveNotifyThunk), this); | |
| 96 | |
| 97 registrar_.Add( | 90 registrar_.Add( |
| 98 this, | 91 this, |
| 99 chrome::NOTIFICATION_PANEL_CHANGED_LAYOUT_MODE, | 92 chrome::NOTIFICATION_PANEL_CHANGED_LAYOUT_MODE, |
| 100 content::Source<Panel>(panel_.get())); | 93 content::Source<Panel>(panel_.get())); |
| 101 registrar_.Add( | 94 registrar_.Add( |
| 102 this, | 95 this, |
| 103 chrome::NOTIFICATION_WINDOW_CLOSED, | 96 chrome::NOTIFICATION_WINDOW_CLOSED, |
| 104 content::Source<GtkWindow>(window())); | 97 content::Source<GtkWindow>(window())); |
| 105 } | 98 } |
| 106 | 99 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 chrome::NOTIFICATION_PANEL_WINDOW_SIZE_KNOWN, | 203 chrome::NOTIFICATION_PANEL_WINDOW_SIZE_KNOWN, |
| 211 content::Source<Panel>(panel_.get()), | 204 content::Source<Panel>(panel_.get()), |
| 212 content::NotificationService::NoDetails()); | 205 content::NotificationService::NoDetails()); |
| 213 } | 206 } |
| 214 | 207 |
| 215 bool PanelBrowserWindowGtk::UseCustomFrame() { | 208 bool PanelBrowserWindowGtk::UseCustomFrame() { |
| 216 // We always use custom frame for panels. | 209 // We always use custom frame for panels. |
| 217 return TRUE; | 210 return TRUE; |
| 218 } | 211 } |
| 219 | 212 |
| 220 void PanelBrowserWindowGtk::ShowSettingsMenu(GtkWidget* widget, | |
| 221 GdkEventButton* event) { | |
| 222 if (!settings_menu_.get()) { | |
| 223 settings_menu_model_.reset(new PanelSettingsMenuModel(panel_.get())); | |
| 224 settings_menu_.reset(new MenuGtk(this, settings_menu_model_.get())); | |
| 225 } | |
| 226 settings_menu_->PopupForWidget(widget, event->button, event->time); | |
| 227 } | |
| 228 | |
| 229 void PanelBrowserWindowGtk::DrawPopupFrame(cairo_t* cr, | 213 void PanelBrowserWindowGtk::DrawPopupFrame(cairo_t* cr, |
| 230 GtkWidget* widget, | 214 GtkWidget* widget, |
| 231 GdkEventExpose* event) { | 215 GdkEventExpose* event) { |
| 232 BrowserWindowGtk::DrawPopupFrame(cr, widget, event); | 216 BrowserWindowGtk::DrawPopupFrame(cr, widget, event); |
| 233 | 217 |
| 234 if (is_drawing_attention_) | 218 if (is_drawing_attention_) |
| 235 DrawAttentionFrame(cr, widget, event); | 219 DrawAttentionFrame(cr, widget, event); |
| 236 } | 220 } |
| 237 | 221 |
| 238 void PanelBrowserWindowGtk::DrawCustomFrame(cairo_t* cr, | 222 void PanelBrowserWindowGtk::DrawCustomFrame(cairo_t* cr, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 261 cairo_paint(cr); | 245 cairo_paint(cr); |
| 262 gdk_region_destroy(dest_region); | 246 gdk_region_destroy(dest_region); |
| 263 } | 247 } |
| 264 | 248 |
| 265 void PanelBrowserWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { | 249 void PanelBrowserWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { |
| 266 bool was_active = IsActive(); | 250 bool was_active = IsActive(); |
| 267 BrowserWindowGtk::ActiveWindowChanged(active_window); | 251 BrowserWindowGtk::ActiveWindowChanged(active_window); |
| 268 if (!window() || was_active == IsActive()) // State didn't change. | 252 if (!window() || was_active == IsActive()) // State didn't change. |
| 269 return; | 253 return; |
| 270 | 254 |
| 271 PanelStrip* panel_strip = panel_->panel_strip(); | |
| 272 if (panel_strip) { | |
| 273 if ((IsActive() || window_has_mouse_) && | |
| 274 panel_strip->type() != PanelStrip::IN_OVERFLOW) { | |
| 275 titlebar()->ShowPanelWrenchButton(); | |
| 276 } else { | |
| 277 titlebar()->HidePanelWrenchButton(); | |
| 278 } | |
| 279 } | |
| 280 | |
| 281 content::NotificationService::current()->Notify( | 255 content::NotificationService::current()->Notify( |
| 282 chrome::NOTIFICATION_PANEL_CHANGED_ACTIVE_STATUS, | 256 chrome::NOTIFICATION_PANEL_CHANGED_ACTIVE_STATUS, |
| 283 content::Source<Panel>(panel_.get()), | 257 content::Source<Panel>(panel_.get()), |
| 284 content::NotificationService::NoDetails()); | 258 content::NotificationService::NoDetails()); |
| 285 } | 259 } |
| 286 | 260 |
| 287 BrowserWindowGtk::TitleDecoration PanelBrowserWindowGtk::GetWindowTitle( | 261 BrowserWindowGtk::TitleDecoration PanelBrowserWindowGtk::GetWindowTitle( |
| 288 std::string* title) const { | 262 std::string* title) const { |
| 289 if (is_drawing_attention_) { | 263 if (is_drawing_attention_) { |
| 290 std::string title_original; | 264 std::string title_original; |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 // drag-end). We post a task, instead of calling EndDrag right here, to give | 771 // drag-end). We post a task, instead of calling EndDrag right here, to give |
| 798 // GTK+ a chance to send the drag-failed event with the right status. If | 772 // GTK+ a chance to send the drag-failed event with the right status. If |
| 799 // GTK+ does send the drag-failed event, we cancel the task. | 773 // GTK+ does send the drag-failed event, we cancel the task. |
| 800 MessageLoop::current()->PostTask(FROM_HERE, | 774 MessageLoop::current()->PostTask(FROM_HERE, |
| 801 base::Bind(&PanelBrowserWindowGtk::EndDrag, | 775 base::Bind(&PanelBrowserWindowGtk::EndDrag, |
| 802 drag_end_factory_.GetWeakPtr(), | 776 drag_end_factory_.GetWeakPtr(), |
| 803 false)); | 777 false)); |
| 804 return TRUE; | 778 return TRUE; |
| 805 } | 779 } |
| 806 | 780 |
| 807 gboolean PanelBrowserWindowGtk::OnEnterNotify(GtkWidget* widget, | |
| 808 GdkEventCrossing* event) { | |
| 809 // Ignore if entered from a child widget. | |
| 810 if (event->detail == GDK_NOTIFY_INFERIOR) | |
| 811 return FALSE; | |
| 812 | |
| 813 PanelStrip* panel_strip = panel_->panel_strip(); | |
| 814 if (!panel_strip) | |
| 815 return FALSE; | |
| 816 | |
| 817 if (window() && panel_strip->type() != PanelStrip::IN_OVERFLOW) | |
| 818 titlebar()->ShowPanelWrenchButton(); | |
| 819 | |
| 820 window_has_mouse_ = true; | |
| 821 return FALSE; | |
| 822 } | |
| 823 | |
| 824 gboolean PanelBrowserWindowGtk::OnLeaveNotify(GtkWidget* widget, | |
| 825 GdkEventCrossing* event) { | |
| 826 // Ignore if left towards a child widget. | |
| 827 if (event->detail == GDK_NOTIFY_INFERIOR) | |
| 828 return FALSE; | |
| 829 | |
| 830 if (window_ && !IsActive()) | |
| 831 titlebar()->HidePanelWrenchButton(); | |
| 832 | |
| 833 window_has_mouse_ = false; | |
| 834 return FALSE; | |
| 835 } | |
| 836 | |
| 837 // NativePanelTesting implementation. | 781 // NativePanelTesting implementation. |
| 838 class NativePanelTestingGtk : public NativePanelTesting { | 782 class NativePanelTestingGtk : public NativePanelTesting { |
| 839 public: | 783 public: |
| 840 explicit NativePanelTestingGtk( | 784 explicit NativePanelTestingGtk( |
| 841 PanelBrowserWindowGtk* panel_browser_window_gtk); | 785 PanelBrowserWindowGtk* panel_browser_window_gtk); |
| 842 | 786 |
| 843 private: | 787 private: |
| 844 virtual void PressLeftMouseButtonTitlebar( | 788 virtual void PressLeftMouseButtonTitlebar( |
| 845 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; | 789 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; |
| 846 virtual void ReleaseMouseButtonTitlebar( | 790 virtual void ReleaseMouseButtonTitlebar( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 MessageLoopForUI::current()->RunAllPending(); | 890 MessageLoopForUI::current()->RunAllPending(); |
| 947 } | 891 } |
| 948 | 892 |
| 949 bool NativePanelTestingGtk::IsWindowSizeKnown() const { | 893 bool NativePanelTestingGtk::IsWindowSizeKnown() const { |
| 950 return !panel_browser_window_gtk_->frame_size_.IsEmpty(); | 894 return !panel_browser_window_gtk_->frame_size_.IsEmpty(); |
| 951 } | 895 } |
| 952 | 896 |
| 953 bool NativePanelTestingGtk::IsAnimatingBounds() const { | 897 bool NativePanelTestingGtk::IsAnimatingBounds() const { |
| 954 return panel_browser_window_gtk_->IsAnimatingBounds(); | 898 return panel_browser_window_gtk_->IsAnimatingBounds(); |
| 955 } | 899 } |
| OLD | NEW |