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 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 DrawContentShadow(cr, window); | 664 DrawContentShadow(cr, window); |
665 | 665 |
666 cairo_destroy(cr); | 666 cairo_destroy(cr); |
667 | 667 |
668 if (window->UseCustomFrame() && !window->IsMaximized()) { | 668 if (window->UseCustomFrame() && !window->IsMaximized()) { |
669 static NineBox custom_frame_border( | 669 static NineBox custom_frame_border( |
670 IDR_WINDOW_TOP_LEFT_CORNER, | 670 IDR_WINDOW_TOP_LEFT_CORNER, |
671 IDR_WINDOW_TOP_CENTER, | 671 IDR_WINDOW_TOP_CENTER, |
672 IDR_WINDOW_TOP_RIGHT_CORNER, | 672 IDR_WINDOW_TOP_RIGHT_CORNER, |
673 IDR_WINDOW_LEFT_SIDE, | 673 IDR_WINDOW_LEFT_SIDE, |
674 NULL, | 674 0, |
675 IDR_WINDOW_RIGHT_SIDE, | 675 IDR_WINDOW_RIGHT_SIDE, |
676 IDR_WINDOW_BOTTOM_LEFT_CORNER, | 676 IDR_WINDOW_BOTTOM_LEFT_CORNER, |
677 IDR_WINDOW_BOTTOM_CENTER, | 677 IDR_WINDOW_BOTTOM_CENTER, |
678 IDR_WINDOW_BOTTOM_RIGHT_CORNER); | 678 IDR_WINDOW_BOTTOM_RIGHT_CORNER); |
679 | 679 |
680 custom_frame_border.RenderToWidget(widget); | 680 custom_frame_border.RenderToWidget(widget); |
681 } | 681 } |
682 | 682 |
683 return FALSE; // Allow subwidgets to paint. | 683 return FALSE; // Allow subwidgets to paint. |
684 } | 684 } |
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1930 } | 1930 } |
1931 | 1931 |
1932 // Handle left, middle and right clicks. In particular, we care about clicks | 1932 // Handle left, middle and right clicks. In particular, we care about clicks |
1933 // in the custom frame border and clicks in the titlebar. | 1933 // in the custom frame border and clicks in the titlebar. |
1934 | 1934 |
1935 // Make the button press coordinate relative to the browser window. | 1935 // Make the button press coordinate relative to the browser window. |
1936 int win_x, win_y; | 1936 int win_x, win_y; |
1937 gdk_window_get_origin(GTK_WIDGET(browser->window_)->window, &win_x, &win_y); | 1937 gdk_window_get_origin(GTK_WIDGET(browser->window_)->window, &win_x, &win_y); |
1938 | 1938 |
1939 GdkWindowEdge edge; | 1939 GdkWindowEdge edge; |
1940 gfx::Point point(event->x_root - win_x, event->y_root - win_y); | 1940 gfx::Point point(static_cast<int>(event->x_root - win_x), |
| 1941 static_cast<int>(event->y_root - win_y)); |
1941 bool has_hit_edge = browser->GetWindowEdge(point.x(), point.y(), &edge); | 1942 bool has_hit_edge = browser->GetWindowEdge(point.x(), point.y(), &edge); |
1942 | 1943 |
1943 // Ignore clicks that are in/below the browser toolbar. | 1944 // Ignore clicks that are in/below the browser toolbar. |
1944 GtkWidget* toolbar = browser->toolbar_->widget(); | 1945 GtkWidget* toolbar = browser->toolbar_->widget(); |
1945 if (!GTK_WIDGET_VISIBLE(toolbar)) { | 1946 if (!GTK_WIDGET_VISIBLE(toolbar)) { |
1946 // If the toolbar is not showing, use the location of web contents as the | 1947 // If the toolbar is not showing, use the location of web contents as the |
1947 // boundary of where to ignore clicks. | 1948 // boundary of where to ignore clicks. |
1948 toolbar = browser->render_area_vbox_; | 1949 toolbar = browser->render_area_vbox_; |
1949 } | 1950 } |
1950 gint toolbar_y; | 1951 gint toolbar_y; |
1951 gtk_widget_get_pointer(toolbar, NULL, &toolbar_y); | 1952 gtk_widget_get_pointer(toolbar, NULL, &toolbar_y); |
1952 bool has_hit_titlebar = !browser->IsFullscreen() && (toolbar_y < 0) | 1953 bool has_hit_titlebar = !browser->IsFullscreen() && (toolbar_y < 0) |
1953 && !has_hit_edge; | 1954 && !has_hit_edge; |
1954 if (event->button == 1) { | 1955 if (event->button == 1) { |
1955 if (GDK_BUTTON_PRESS == event->type) { | 1956 if (GDK_BUTTON_PRESS == event->type) { |
1956 guint32 last_click_time = browser->last_click_time_; | 1957 guint32 last_click_time = browser->last_click_time_; |
1957 gfx::Point last_click_position = browser->last_click_position_; | 1958 gfx::Point last_click_position = browser->last_click_position_; |
1958 browser->last_click_time_ = event->time; | 1959 browser->last_click_time_ = event->time; |
1959 browser->last_click_position_ = gfx::Point(event->x, event->y); | 1960 browser->last_click_position_ = gfx::Point(static_cast<int>(event->x), |
| 1961 static_cast<int>(event->y)); |
1960 | 1962 |
1961 if (has_hit_titlebar) { | 1963 if (has_hit_titlebar) { |
1962 // We want to start a move when the user single clicks, but not start a | 1964 // We want to start a move when the user single clicks, but not start a |
1963 // move when the user double clicks. However, a double click sends the | 1965 // move when the user double clicks. However, a double click sends the |
1964 // following GDK events: GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE, | 1966 // following GDK events: GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE, |
1965 // GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_BUTTON_RELEASE. If we | 1967 // GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_BUTTON_RELEASE. If we |
1966 // start a gtk_window_begin_move_drag on the second GDK_BUTTON_PRESS, | 1968 // start a gtk_window_begin_move_drag on the second GDK_BUTTON_PRESS, |
1967 // the call to gtk_window_maximize fails. To work around this, we | 1969 // the call to gtk_window_maximize fails. To work around this, we |
1968 // keep track of the last click and if it's going to be a double click, | 1970 // keep track of the last click and if it's going to be a double click, |
1969 // we don't call gtk_window_begin_move_drag. | 1971 // we don't call gtk_window_begin_move_drag. |
1970 static GtkSettings* settings = gtk_settings_get_default(); | 1972 static GtkSettings* settings = gtk_settings_get_default(); |
1971 gint double_click_time = 250; | 1973 gint double_click_time = 250; |
1972 gint double_click_distance = 5; | 1974 gint double_click_distance = 5; |
1973 g_object_get(G_OBJECT(settings), | 1975 g_object_get(G_OBJECT(settings), |
1974 "gtk-double-click-time", &double_click_time, | 1976 "gtk-double-click-time", &double_click_time, |
1975 "gtk-double-click-distance", &double_click_distance, | 1977 "gtk-double-click-distance", &double_click_distance, |
1976 NULL); | 1978 NULL); |
1977 | 1979 |
1978 guint32 click_time = event->time - last_click_time; | 1980 guint32 click_time = event->time - last_click_time; |
1979 int click_move_x = event->x - last_click_position.x(); | 1981 int click_move_x = static_cast<int>(event->x - last_click_position.x()); |
1980 int click_move_y = event->y - last_click_position.y(); | 1982 int click_move_y = static_cast<int>(event->y - last_click_position.y()); |
1981 | 1983 |
1982 if (click_time > static_cast<guint32>(double_click_time) || | 1984 if (click_time > static_cast<guint32>(double_click_time) || |
1983 click_move_x > double_click_distance || | 1985 click_move_x > double_click_distance || |
1984 click_move_y > double_click_distance) { | 1986 click_move_y > double_click_distance) { |
1985 gtk_window_begin_move_drag(browser->window_, event->button, | 1987 gtk_window_begin_move_drag(browser->window_, event->button, |
1986 event->x_root, event->y_root, event->time); | 1988 static_cast<gint>(event->x_root), |
| 1989 static_cast<gint>(event->y_root), |
| 1990 event->time); |
1987 return TRUE; | 1991 return TRUE; |
1988 } | 1992 } |
1989 } else if (has_hit_edge) { | 1993 } else if (has_hit_edge) { |
1990 gtk_window_begin_resize_drag(browser->window_, edge, event->button, | 1994 gtk_window_begin_resize_drag(browser->window_, edge, event->button, |
1991 event->x_root, event->y_root, event->time); | 1995 static_cast<gint>(event->x_root), |
| 1996 static_cast<gint>(event->y_root), |
| 1997 event->time); |
1992 return TRUE; | 1998 return TRUE; |
1993 } | 1999 } |
1994 } else if (GDK_2BUTTON_PRESS == event->type) { | 2000 } else if (GDK_2BUTTON_PRESS == event->type) { |
1995 if (has_hit_titlebar) { | 2001 if (has_hit_titlebar) { |
1996 // Maximize/restore on double click. | 2002 // Maximize/restore on double click. |
1997 if (browser->IsMaximized()) { | 2003 if (browser->IsMaximized()) { |
1998 gtk_window_unmaximize(browser->window_); | 2004 gtk_window_unmaximize(browser->window_); |
1999 } else { | 2005 } else { |
2000 gtk_window_maximize(browser->window_); | 2006 gtk_window_maximize(browser->window_); |
2001 } | 2007 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2195 // special-case the ones where the custom frame should be used. These names | 2201 // special-case the ones where the custom frame should be used. These names |
2196 // are taken from the WMs' source code. | 2202 // are taken from the WMs' source code. |
2197 return (wm_name == "Blackbox" || | 2203 return (wm_name == "Blackbox" || |
2198 wm_name == "compiz" || | 2204 wm_name == "compiz" || |
2199 wm_name == "e16" || // Enlightenment DR16 | 2205 wm_name == "e16" || // Enlightenment DR16 |
2200 wm_name == "KWin" || | 2206 wm_name == "KWin" || |
2201 wm_name == "Metacity" || | 2207 wm_name == "Metacity" || |
2202 wm_name == "Openbox" || | 2208 wm_name == "Openbox" || |
2203 wm_name == "Xfwm4"); | 2209 wm_name == "Xfwm4"); |
2204 } | 2210 } |
OLD | NEW |