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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 DrawContentShadow(cr, window); | 631 DrawContentShadow(cr, window); |
632 | 632 |
633 cairo_destroy(cr); | 633 cairo_destroy(cr); |
634 | 634 |
635 if (window->UseCustomFrame() && !window->IsMaximized()) { | 635 if (window->UseCustomFrame() && !window->IsMaximized()) { |
636 static NineBox custom_frame_border( | 636 static NineBox custom_frame_border( |
637 IDR_WINDOW_TOP_LEFT_CORNER, | 637 IDR_WINDOW_TOP_LEFT_CORNER, |
638 IDR_WINDOW_TOP_CENTER, | 638 IDR_WINDOW_TOP_CENTER, |
639 IDR_WINDOW_TOP_RIGHT_CORNER, | 639 IDR_WINDOW_TOP_RIGHT_CORNER, |
640 IDR_WINDOW_LEFT_SIDE, | 640 IDR_WINDOW_LEFT_SIDE, |
641 NULL, | 641 0, |
642 IDR_WINDOW_RIGHT_SIDE, | 642 IDR_WINDOW_RIGHT_SIDE, |
643 IDR_WINDOW_BOTTOM_LEFT_CORNER, | 643 IDR_WINDOW_BOTTOM_LEFT_CORNER, |
644 IDR_WINDOW_BOTTOM_CENTER, | 644 IDR_WINDOW_BOTTOM_CENTER, |
645 IDR_WINDOW_BOTTOM_RIGHT_CORNER); | 645 IDR_WINDOW_BOTTOM_RIGHT_CORNER); |
646 | 646 |
647 custom_frame_border.RenderToWidget(widget); | 647 custom_frame_border.RenderToWidget(widget); |
648 } | 648 } |
649 | 649 |
650 return FALSE; // Allow subwidgets to paint. | 650 return FALSE; // Allow subwidgets to paint. |
651 } | 651 } |
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1891 } | 1891 } |
1892 | 1892 |
1893 // Handle left, middle and right clicks. In particular, we care about clicks | 1893 // Handle left, middle and right clicks. In particular, we care about clicks |
1894 // in the custom frame border and clicks in the titlebar. | 1894 // in the custom frame border and clicks in the titlebar. |
1895 | 1895 |
1896 // Make the button press coordinate relative to the browser window. | 1896 // Make the button press coordinate relative to the browser window. |
1897 int win_x, win_y; | 1897 int win_x, win_y; |
1898 gdk_window_get_origin(GTK_WIDGET(browser->window_)->window, &win_x, &win_y); | 1898 gdk_window_get_origin(GTK_WIDGET(browser->window_)->window, &win_x, &win_y); |
1899 | 1899 |
1900 GdkWindowEdge edge; | 1900 GdkWindowEdge edge; |
1901 gfx::Point point(event->x_root - win_x, event->y_root - win_y); | 1901 gfx::Point point(static_cast<int>(event->x_root - win_x), |
| 1902 static_cast<int>(event->y_root - win_y)); |
1902 bool has_hit_edge = browser->GetWindowEdge(point.x(), point.y(), &edge); | 1903 bool has_hit_edge = browser->GetWindowEdge(point.x(), point.y(), &edge); |
1903 | 1904 |
1904 // Ignore clicks that are in/below the browser toolbar. | 1905 // Ignore clicks that are in/below the browser toolbar. |
1905 GtkWidget* toolbar = browser->toolbar_->widget(); | 1906 GtkWidget* toolbar = browser->toolbar_->widget(); |
1906 if (!GTK_WIDGET_VISIBLE(toolbar)) { | 1907 if (!GTK_WIDGET_VISIBLE(toolbar)) { |
1907 // If the toolbar is not showing, use the location of web contents as the | 1908 // If the toolbar is not showing, use the location of web contents as the |
1908 // boundary of where to ignore clicks. | 1909 // boundary of where to ignore clicks. |
1909 toolbar = browser->render_area_vbox_; | 1910 toolbar = browser->render_area_vbox_; |
1910 } | 1911 } |
1911 gint toolbar_y; | 1912 gint toolbar_y; |
1912 gtk_widget_get_pointer(toolbar, NULL, &toolbar_y); | 1913 gtk_widget_get_pointer(toolbar, NULL, &toolbar_y); |
1913 bool has_hit_titlebar = !browser->IsFullscreen() && (toolbar_y < 0) | 1914 bool has_hit_titlebar = !browser->IsFullscreen() && (toolbar_y < 0) |
1914 && !has_hit_edge; | 1915 && !has_hit_edge; |
1915 if (event->button == 1) { | 1916 if (event->button == 1) { |
1916 if (GDK_BUTTON_PRESS == event->type) { | 1917 if (GDK_BUTTON_PRESS == event->type) { |
1917 guint32 last_click_time = browser->last_click_time_; | 1918 guint32 last_click_time = browser->last_click_time_; |
1918 gfx::Point last_click_position = browser->last_click_position_; | 1919 gfx::Point last_click_position = browser->last_click_position_; |
1919 browser->last_click_time_ = event->time; | 1920 browser->last_click_time_ = event->time; |
1920 browser->last_click_position_ = gfx::Point(event->x, event->y); | 1921 browser->last_click_position_ = gfx::Point(static_cast<int>(event->x), |
| 1922 static_cast<int>(event->y)); |
1921 | 1923 |
1922 if (has_hit_titlebar) { | 1924 if (has_hit_titlebar) { |
1923 // We want to start a move when the user single clicks, but not start a | 1925 // We want to start a move when the user single clicks, but not start a |
1924 // move when the user double clicks. However, a double click sends the | 1926 // move when the user double clicks. However, a double click sends the |
1925 // following GDK events: GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE, | 1927 // following GDK events: GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE, |
1926 // GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_BUTTON_RELEASE. If we | 1928 // GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_BUTTON_RELEASE. If we |
1927 // start a gtk_window_begin_move_drag on the second GDK_BUTTON_PRESS, | 1929 // start a gtk_window_begin_move_drag on the second GDK_BUTTON_PRESS, |
1928 // the call to gtk_window_maximize fails. To work around this, we | 1930 // the call to gtk_window_maximize fails. To work around this, we |
1929 // keep track of the last click and if it's going to be a double click, | 1931 // keep track of the last click and if it's going to be a double click, |
1930 // we don't call gtk_window_begin_move_drag. | 1932 // we don't call gtk_window_begin_move_drag. |
1931 static GtkSettings* settings = gtk_settings_get_default(); | 1933 static GtkSettings* settings = gtk_settings_get_default(); |
1932 gint double_click_time = 250; | 1934 gint double_click_time = 250; |
1933 gint double_click_distance = 5; | 1935 gint double_click_distance = 5; |
1934 g_object_get(G_OBJECT(settings), | 1936 g_object_get(G_OBJECT(settings), |
1935 "gtk-double-click-time", &double_click_time, | 1937 "gtk-double-click-time", &double_click_time, |
1936 "gtk-double-click-distance", &double_click_distance, | 1938 "gtk-double-click-distance", &double_click_distance, |
1937 NULL); | 1939 NULL); |
1938 | 1940 |
1939 guint32 click_time = event->time - last_click_time; | 1941 guint32 click_time = event->time - last_click_time; |
1940 int click_move_x = event->x - last_click_position.x(); | 1942 int click_move_x = static_cast<int>(event->x - last_click_position.x()); |
1941 int click_move_y = event->y - last_click_position.y(); | 1943 int click_move_y = static_cast<int>(event->y - last_click_position.y()); |
1942 | 1944 |
1943 if (click_time > static_cast<guint32>(double_click_time) || | 1945 if (click_time > static_cast<guint32>(double_click_time) || |
1944 click_move_x > double_click_distance || | 1946 click_move_x > double_click_distance || |
1945 click_move_y > double_click_distance) { | 1947 click_move_y > double_click_distance) { |
1946 gtk_window_begin_move_drag(browser->window_, event->button, | 1948 gtk_window_begin_move_drag(browser->window_, event->button, |
1947 event->x_root, event->y_root, event->time); | 1949 static_cast<gint>(event->x_root), |
| 1950 static_cast<gint>(event->y_root), |
| 1951 event->time); |
1948 return TRUE; | 1952 return TRUE; |
1949 } | 1953 } |
1950 } else if (has_hit_edge) { | 1954 } else if (has_hit_edge) { |
1951 gtk_window_begin_resize_drag(browser->window_, edge, event->button, | 1955 gtk_window_begin_resize_drag(browser->window_, edge, event->button, |
1952 event->x_root, event->y_root, event->time); | 1956 static_cast<gint>(event->x_root), |
| 1957 static_cast<gint>(event->y_root), |
| 1958 event->time); |
1953 return TRUE; | 1959 return TRUE; |
1954 } | 1960 } |
1955 } else if (GDK_2BUTTON_PRESS == event->type) { | 1961 } else if (GDK_2BUTTON_PRESS == event->type) { |
1956 if (has_hit_titlebar) { | 1962 if (has_hit_titlebar) { |
1957 // Maximize/restore on double click. | 1963 // Maximize/restore on double click. |
1958 if (browser->IsMaximized()) { | 1964 if (browser->IsMaximized()) { |
1959 gtk_window_unmaximize(browser->window_); | 1965 gtk_window_unmaximize(browser->window_); |
1960 } else { | 1966 } else { |
1961 gtk_window_maximize(browser->window_); | 1967 gtk_window_maximize(browser->window_); |
1962 } | 1968 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2156 // special-case the ones where the custom frame should be used. These names | 2162 // special-case the ones where the custom frame should be used. These names |
2157 // are taken from the WMs' source code. | 2163 // are taken from the WMs' source code. |
2158 return (wm_name == "Blackbox" || | 2164 return (wm_name == "Blackbox" || |
2159 wm_name == "compiz" || | 2165 wm_name == "compiz" || |
2160 wm_name == "e16" || // Enlightenment DR16 | 2166 wm_name == "e16" || // Enlightenment DR16 |
2161 wm_name == "KWin" || | 2167 wm_name == "KWin" || |
2162 wm_name == "Metacity" || | 2168 wm_name == "Metacity" || |
2163 wm_name == "Openbox" || | 2169 wm_name == "Openbox" || |
2164 wm_name == "Xfwm4"); | 2170 wm_name == "Xfwm4"); |
2165 } | 2171 } |
OLD | NEW |