| 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_manager.h" | 13 #include "chrome/browser/ui/panels/panel_manager.h" |
| 13 #include "chrome/browser/ui/panels/panel_strip.h" | 14 #include "chrome/browser/ui/panels/panel_strip.h" |
| 14 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" | 15 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 17 #include "ui/base/dragdrop/gtk_dnd_util.h" | 18 #include "ui/base/dragdrop/gtk_dnd_util.h" |
| 18 | 19 |
| 19 using content::WebContents; | 20 using content::WebContents; |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 34 | 35 |
| 35 // Markup for title text in draw attention state. Set to color white. | 36 // Markup for title text in draw attention state. Set to color white. |
| 36 const char* const kDrawAttentionTitleMarkupPrefix = | 37 const char* const kDrawAttentionTitleMarkupPrefix = |
| 37 "<span fgcolor='#ffffff'>"; | 38 "<span fgcolor='#ffffff'>"; |
| 38 const char* const kDrawAttentionTitleMarkupSuffix = "</span>"; | 39 const char* const kDrawAttentionTitleMarkupSuffix = "</span>"; |
| 39 | 40 |
| 40 // Set minimium width for window really small so it can be reduced to icon only | 41 // Set minimium width for window really small so it can be reduced to icon only |
| 41 // size in overflow expansion state. | 42 // size in overflow expansion state. |
| 42 const int kMinWindowWidth = 2; | 43 const int kMinWindowWidth = 2; |
| 43 | 44 |
| 44 } | 45 } // namespace |
| 45 | 46 |
| 46 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, | 47 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, |
| 47 const gfx::Rect& bounds) { | 48 const gfx::Rect& bounds) { |
| 48 PanelBrowserWindowGtk* panel_browser_window_gtk = | 49 PanelBrowserWindowGtk* panel_browser_window_gtk = |
| 49 new PanelBrowserWindowGtk(browser, panel, bounds); | 50 new PanelBrowserWindowGtk(browser, panel, bounds); |
| 50 panel_browser_window_gtk->Init(); | 51 panel_browser_window_gtk->Init(); |
| 51 return panel_browser_window_gtk; | 52 return panel_browser_window_gtk; |
| 52 } | 53 } |
| 53 | 54 |
| 54 PanelBrowserWindowGtk::PanelBrowserWindowGtk(Browser* browser, | 55 PanelBrowserWindowGtk::PanelBrowserWindowGtk(Browser* browser, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 this, | 98 this, |
| 98 chrome::NOTIFICATION_PANEL_CHANGED_LAYOUT_MODE, | 99 chrome::NOTIFICATION_PANEL_CHANGED_LAYOUT_MODE, |
| 99 content::Source<Panel>(panel_.get())); | 100 content::Source<Panel>(panel_.get())); |
| 100 registrar_.Add( | 101 registrar_.Add( |
| 101 this, | 102 this, |
| 102 chrome::NOTIFICATION_WINDOW_CLOSED, | 103 chrome::NOTIFICATION_WINDOW_CLOSED, |
| 103 content::Source<GtkWindow>(window())); | 104 content::Source<GtkWindow>(window())); |
| 104 } | 105 } |
| 105 | 106 |
| 106 bool PanelBrowserWindowGtk::GetWindowEdge(int x, int y, GdkWindowEdge* edge) { | 107 bool PanelBrowserWindowGtk::GetWindowEdge(int x, int y, GdkWindowEdge* edge) { |
| 107 // Since panels are not resizable or movable by the user, we should not | 108 // Only detect the window edge when panels can be resized by the user. |
| 108 // detect the window edge for behavioral purposes. The edge, if any, | 109 // This method is used by the base class to detect when the cursor has |
| 109 // is present only for visual aspects. | 110 // hit the window edge in order to change the cursor to a resize cursor |
| 110 return FALSE; | 111 // and to detect when to initiate a resize drag. |
| 112 return panel_->CanResizeByMouse() ? |
| 113 BrowserWindowGtk::GetWindowEdge(x, y, edge) : FALSE; |
| 114 } |
| 115 |
| 116 void PanelBrowserWindowGtk::EnsureDragHelperCreated() { |
| 117 if (drag_helper_.get()) |
| 118 return; |
| 119 |
| 120 drag_helper_.reset(new PanelDragGtk(panel_.get())); |
| 121 gtk_box_pack_end(GTK_BOX(window_vbox_), drag_helper_->widget(), |
| 122 FALSE, FALSE, 0); |
| 111 } | 123 } |
| 112 | 124 |
| 113 bool PanelBrowserWindowGtk::HandleTitleBarLeftMousePress( | 125 bool PanelBrowserWindowGtk::HandleTitleBarLeftMousePress( |
| 114 GdkEventButton* event, | 126 GdkEventButton* event, |
| 115 guint32 last_click_time, | 127 guint32 last_click_time, |
| 116 gfx::Point last_click_position) { | 128 gfx::Point last_click_position) { |
| 117 // In theory we should never enter this function as we have a handler for | 129 // In theory we should never enter this function as we have a handler for |
| 118 // button press on titlebar where we handle this. Not putting NOTREACHED() | 130 // button press on titlebar where we handle this. Not putting NOTREACHED() |
| 119 // here because we don't want to crash if hit-testing for titlebar in window | 131 // here because we don't want to crash if hit-testing for titlebar in window |
| 120 // button press handler in BrowserWindowGtk is off by a pixel or two. | 132 // button press handler in BrowserWindowGtk is off by a pixel or two. |
| 121 DLOG(WARNING) << "Hit-testing for titlebar off by a pixel or two?"; | 133 DLOG(WARNING) << "Hit-testing for titlebar off by a pixel or two?"; |
| 122 return TRUE; | 134 return TRUE; |
| 123 } | 135 } |
| 124 | 136 |
| 137 bool PanelBrowserWindowGtk::HandleWindowEdgeLeftMousePress( |
| 138 GtkWindow* window, |
| 139 GdkWindowEdge edge, |
| 140 GdkEventButton* event) { |
| 141 DCHECK_EQ(1U, event->button); |
| 142 DCHECK_EQ(GDK_BUTTON_PRESS, event->type); |
| 143 |
| 144 EnsureDragHelperCreated(); |
| 145 // Resize cursor was set by BrowserWindowGtk when mouse moved over |
| 146 // window edge. |
| 147 GdkCursor* cursor = |
| 148 gdk_window_get_cursor(gtk_widget_get_window(GTK_WIDGET(window_))); |
| 149 drag_helper_->InitialWindowEdgeMousePress(event, cursor, edge); |
| 150 return TRUE; |
| 151 } |
| 152 |
| 125 void PanelBrowserWindowGtk::SaveWindowPosition() { | 153 void PanelBrowserWindowGtk::SaveWindowPosition() { |
| 126 // We don't save window position for panels as it's controlled by | 154 // We don't save window position for panels as it's controlled by |
| 127 // PanelManager. | 155 // PanelManager. |
| 128 return; | 156 return; |
| 129 } | 157 } |
| 130 | 158 |
| 131 void PanelBrowserWindowGtk::SetGeometryHints() { | 159 void PanelBrowserWindowGtk::SetGeometryHints() { |
| 132 // Set minimum height the window can be set to. | 160 // Set minimum height the window can be set to. |
| 133 GdkGeometry hints; | 161 GdkGeometry hints; |
| 134 hints.min_height = Panel::kMinimizedPanelHeight; | 162 hints.min_height = Panel::kMinimizedPanelHeight; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 bounds_animator_.reset(); | 307 bounds_animator_.reset(); |
| 280 | 308 |
| 281 CleanupDragDrop(); | 309 CleanupDragDrop(); |
| 282 if (drag_widget_) { | 310 if (drag_widget_) { |
| 283 // Terminate the grab if we have it. We could do this using any widget, | 311 // Terminate the grab if we have it. We could do this using any widget, |
| 284 // |drag_widget_| is just convenient. | 312 // |drag_widget_| is just convenient. |
| 285 gtk_grab_add(drag_widget_); | 313 gtk_grab_add(drag_widget_); |
| 286 gtk_grab_remove(drag_widget_); | 314 gtk_grab_remove(drag_widget_); |
| 287 DestroyDragWidget(); | 315 DestroyDragWidget(); |
| 288 } | 316 } |
| 317 |
| 318 if (drag_helper_.get()) |
| 319 drag_helper_.reset(); |
| 320 |
| 289 panel_->OnNativePanelClosed(); | 321 panel_->OnNativePanelClosed(); |
| 290 break; | 322 break; |
| 291 } | 323 } |
| 292 | 324 |
| 293 BrowserWindowGtk::Observe(type, source, details); | 325 BrowserWindowGtk::Observe(type, source, details); |
| 294 } | 326 } |
| 295 | 327 |
| 296 void PanelBrowserWindowGtk::ShowPanel() { | 328 void PanelBrowserWindowGtk::ShowPanel() { |
| 297 Show(); | 329 Show(); |
| 298 } | 330 } |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 MessageLoopForUI::current()->RunAllPending(); | 933 MessageLoopForUI::current()->RunAllPending(); |
| 902 } | 934 } |
| 903 | 935 |
| 904 bool NativePanelTestingGtk::IsWindowSizeKnown() const { | 936 bool NativePanelTestingGtk::IsWindowSizeKnown() const { |
| 905 return !panel_browser_window_gtk_->frame_size_.IsEmpty(); | 937 return !panel_browser_window_gtk_->frame_size_.IsEmpty(); |
| 906 } | 938 } |
| 907 | 939 |
| 908 bool NativePanelTestingGtk::IsAnimatingBounds() const { | 940 bool NativePanelTestingGtk::IsAnimatingBounds() const { |
| 909 return panel_browser_window_gtk_->IsAnimatingBounds(); | 941 return panel_browser_window_gtk_->IsAnimatingBounds(); |
| 910 } | 942 } |
| OLD | NEW |