| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk/browser_window_gtk.h" | 5 #include "chrome/browser/gtk/browser_window_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
| 8 #include <X11/XF86keysym.h> | 8 #include <X11/XF86keysym.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 DrawContentShadow(cr, window); | 596 DrawContentShadow(cr, window); |
| 597 | 597 |
| 598 cairo_destroy(cr); | 598 cairo_destroy(cr); |
| 599 | 599 |
| 600 if (window->UseCustomFrame() && !window->IsMaximized()) { | 600 if (window->UseCustomFrame() && !window->IsMaximized()) { |
| 601 static NineBox custom_frame_border( | 601 static NineBox custom_frame_border( |
| 602 IDR_WINDOW_TOP_LEFT_CORNER, | 602 IDR_WINDOW_TOP_LEFT_CORNER, |
| 603 IDR_WINDOW_TOP_CENTER, | 603 IDR_WINDOW_TOP_CENTER, |
| 604 IDR_WINDOW_TOP_RIGHT_CORNER, | 604 IDR_WINDOW_TOP_RIGHT_CORNER, |
| 605 IDR_WINDOW_LEFT_SIDE, | 605 IDR_WINDOW_LEFT_SIDE, |
| 606 0, | 606 NULL, |
| 607 IDR_WINDOW_RIGHT_SIDE, | 607 IDR_WINDOW_RIGHT_SIDE, |
| 608 IDR_WINDOW_BOTTOM_LEFT_CORNER, | 608 IDR_WINDOW_BOTTOM_LEFT_CORNER, |
| 609 IDR_WINDOW_BOTTOM_CENTER, | 609 IDR_WINDOW_BOTTOM_CENTER, |
| 610 IDR_WINDOW_BOTTOM_RIGHT_CORNER); | 610 IDR_WINDOW_BOTTOM_RIGHT_CORNER); |
| 611 | 611 |
| 612 custom_frame_border.RenderToWidget(widget); | 612 custom_frame_border.RenderToWidget(widget); |
| 613 } | 613 } |
| 614 | 614 |
| 615 return FALSE; // Allow subwidgets to paint. | 615 return FALSE; // Allow subwidgets to paint. |
| 616 } | 616 } |
| (...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 } | 1818 } |
| 1819 | 1819 |
| 1820 // Handle left, middle and right clicks. In particular, we care about clicks | 1820 // Handle left, middle and right clicks. In particular, we care about clicks |
| 1821 // in the custom frame border and clicks in the titlebar. | 1821 // in the custom frame border and clicks in the titlebar. |
| 1822 | 1822 |
| 1823 // Make the button press coordinate relative to the browser window. | 1823 // Make the button press coordinate relative to the browser window. |
| 1824 int win_x, win_y; | 1824 int win_x, win_y; |
| 1825 gdk_window_get_origin(GTK_WIDGET(browser->window_)->window, &win_x, &win_y); | 1825 gdk_window_get_origin(GTK_WIDGET(browser->window_)->window, &win_x, &win_y); |
| 1826 | 1826 |
| 1827 GdkWindowEdge edge; | 1827 GdkWindowEdge edge; |
| 1828 gfx::Point point(static_cast<int>(event->x_root - win_x), | 1828 gfx::Point point(event->x_root - win_x, event->y_root - win_y); |
| 1829 static_cast<int>( event->y_root - win_y)); | |
| 1830 bool has_hit_edge = browser->GetWindowEdge(point.x(), point.y(), &edge); | 1829 bool has_hit_edge = browser->GetWindowEdge(point.x(), point.y(), &edge); |
| 1831 | 1830 |
| 1832 // Ignore clicks that are in/below the browser toolbar. | 1831 // Ignore clicks that are in/below the browser toolbar. |
| 1833 GtkWidget* toolbar = browser->toolbar_->widget(); | 1832 GtkWidget* toolbar = browser->toolbar_->widget(); |
| 1834 if (!GTK_WIDGET_VISIBLE(toolbar)) { | 1833 if (!GTK_WIDGET_VISIBLE(toolbar)) { |
| 1835 // If the toolbar is not showing, use the location of web contents as the | 1834 // If the toolbar is not showing, use the location of web contents as the |
| 1836 // boundary of where to ignore clicks. | 1835 // boundary of where to ignore clicks. |
| 1837 toolbar = browser->render_area_vbox_; | 1836 toolbar = browser->render_area_vbox_; |
| 1838 } | 1837 } |
| 1839 gint toolbar_y; | 1838 gint toolbar_y; |
| 1840 gtk_widget_get_pointer(toolbar, NULL, &toolbar_y); | 1839 gtk_widget_get_pointer(toolbar, NULL, &toolbar_y); |
| 1841 bool has_hit_titlebar = !browser->IsFullscreen() && (toolbar_y < 0) | 1840 bool has_hit_titlebar = !browser->IsFullscreen() && (toolbar_y < 0) |
| 1842 && !has_hit_edge; | 1841 && !has_hit_edge; |
| 1843 if (event->button == 1) { | 1842 if (event->button == 1) { |
| 1844 if (GDK_BUTTON_PRESS == event->type) { | 1843 if (GDK_BUTTON_PRESS == event->type) { |
| 1845 guint32 last_click_time = browser->last_click_time_; | 1844 guint32 last_click_time = browser->last_click_time_; |
| 1846 gfx::Point last_click_position = browser->last_click_position_; | 1845 gfx::Point last_click_position = browser->last_click_position_; |
| 1847 browser->last_click_time_ = event->time; | 1846 browser->last_click_time_ = event->time; |
| 1848 browser->last_click_position_ = gfx::Point(static_cast<int>(event->x), | 1847 browser->last_click_position_ = gfx::Point(event->x, event->y); |
| 1849 static_cast<int>(event->y)); | |
| 1850 | 1848 |
| 1851 if (has_hit_titlebar) { | 1849 if (has_hit_titlebar) { |
| 1852 // We want to start a move when the user single clicks, but not start a | 1850 // We want to start a move when the user single clicks, but not start a |
| 1853 // move when the user double clicks. However, a double click sends the | 1851 // move when the user double clicks. However, a double click sends the |
| 1854 // following GDK events: GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE, | 1852 // following GDK events: GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE, |
| 1855 // GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_BUTTON_RELEASE. If we | 1853 // GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_BUTTON_RELEASE. If we |
| 1856 // start a gtk_window_begin_move_drag on the second GDK_BUTTON_PRESS, | 1854 // start a gtk_window_begin_move_drag on the second GDK_BUTTON_PRESS, |
| 1857 // the call to gtk_window_maximize fails. To work around this, we | 1855 // the call to gtk_window_maximize fails. To work around this, we |
| 1858 // keep track of the last click and if it's going to be a double click, | 1856 // keep track of the last click and if it's going to be a double click, |
| 1859 // we don't call gtk_window_begin_move_drag. | 1857 // we don't call gtk_window_begin_move_drag. |
| 1860 static GtkSettings* settings = gtk_settings_get_default(); | 1858 static GtkSettings* settings = gtk_settings_get_default(); |
| 1861 gint double_click_time = 250; | 1859 gint double_click_time = 250; |
| 1862 gint double_click_distance = 5; | 1860 gint double_click_distance = 5; |
| 1863 g_object_get(G_OBJECT(settings), | 1861 g_object_get(G_OBJECT(settings), |
| 1864 "gtk-double-click-time", &double_click_time, | 1862 "gtk-double-click-time", &double_click_time, |
| 1865 "gtk-double-click-distance", &double_click_distance, | 1863 "gtk-double-click-distance", &double_click_distance, |
| 1866 NULL); | 1864 NULL); |
| 1867 | 1865 |
| 1868 guint32 click_time = event->time - last_click_time; | 1866 guint32 click_time = event->time - last_click_time; |
| 1869 int click_move_x = static_cast<int>(event->x - last_click_position.x()); | 1867 int click_move_x = event->x - last_click_position.x(); |
| 1870 int click_move_y = static_cast<int>(event->y - last_click_position.y()); | 1868 int click_move_y = event->y - last_click_position.y(); |
| 1871 | 1869 |
| 1872 if (click_time > static_cast<guint32>(double_click_time) || | 1870 if (click_time > static_cast<guint32>(double_click_time) || |
| 1873 click_move_x > double_click_distance || | 1871 click_move_x > double_click_distance || |
| 1874 click_move_y > double_click_distance) { | 1872 click_move_y > double_click_distance) { |
| 1875 gtk_window_begin_move_drag(browser->window_, event->button, | 1873 gtk_window_begin_move_drag(browser->window_, event->button, |
| 1876 static_cast<gint>(event->x_root), | 1874 event->x_root, event->y_root, event->time); |
| 1877 static_cast<gint>(event->y_root), | |
| 1878 event->time); | |
| 1879 return TRUE; | 1875 return TRUE; |
| 1880 } | 1876 } |
| 1881 } else if (has_hit_edge) { | 1877 } else if (has_hit_edge) { |
| 1882 gtk_window_begin_resize_drag(browser->window_, edge, event->button, | 1878 gtk_window_begin_resize_drag(browser->window_, edge, event->button, |
| 1883 static_cast<gint>(event->x_root), | 1879 event->x_root, event->y_root, event->time); |
| 1884 static_cast<gint>(event->y_root), | |
| 1885 event->time); | |
| 1886 return TRUE; | 1880 return TRUE; |
| 1887 } | 1881 } |
| 1888 } else if (GDK_2BUTTON_PRESS == event->type) { | 1882 } else if (GDK_2BUTTON_PRESS == event->type) { |
| 1889 if (has_hit_titlebar) { | 1883 if (has_hit_titlebar) { |
| 1890 // Maximize/restore on double click. | 1884 // Maximize/restore on double click. |
| 1891 if (browser->IsMaximized()) { | 1885 if (browser->IsMaximized()) { |
| 1892 gtk_window_unmaximize(browser->window_); | 1886 gtk_window_unmaximize(browser->window_); |
| 1893 } else { | 1887 } else { |
| 1894 gtk_window_maximize(browser->window_); | 1888 gtk_window_maximize(browser->window_); |
| 1895 } | 1889 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2090 // special-case the ones where the custom frame should be used. These names | 2084 // special-case the ones where the custom frame should be used. These names |
| 2091 // are taken from the WMs' source code. | 2085 // are taken from the WMs' source code. |
| 2092 return (wm_name == "Blackbox" || | 2086 return (wm_name == "Blackbox" || |
| 2093 wm_name == "compiz" || | 2087 wm_name == "compiz" || |
| 2094 wm_name == "e16" || // Enlightenment DR16 | 2088 wm_name == "e16" || // Enlightenment DR16 |
| 2095 wm_name == "KWin" || | 2089 wm_name == "KWin" || |
| 2096 wm_name == "Metacity" || | 2090 wm_name == "Metacity" || |
| 2097 wm_name == "Openbox" || | 2091 wm_name == "Openbox" || |
| 2098 wm_name == "Xfwm4"); | 2092 wm_name == "Xfwm4"); |
| 2099 } | 2093 } |
| OLD | NEW |