Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1026)

Side by Side Diff: chrome/browser/tab_contents/tab_contents_view_gtk.cc

Issue 147246: Linux: middle-click to navigate (Closed)
Patch Set: ... Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/tab_contents/tab_contents_view_gtk.h" 5 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
6 6
7 #include <gdk/gdk.h> 7 #include <gdk/gdk.h>
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 9
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/renderer_host/render_view_host.h" 21 #include "chrome/browser/renderer_host/render_view_host.h"
22 #include "chrome/browser/renderer_host/render_view_host_factory.h" 22 #include "chrome/browser/renderer_host/render_view_host_factory.h"
23 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" 23 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
24 #include "chrome/browser/tab_contents/interstitial_page.h" 24 #include "chrome/browser/tab_contents/interstitial_page.h"
25 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" 25 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h"
26 #include "chrome/browser/tab_contents/tab_contents.h" 26 #include "chrome/browser/tab_contents/tab_contents.h"
27 #include "chrome/browser/tab_contents/tab_contents_delegate.h" 27 #include "chrome/browser/tab_contents/tab_contents_delegate.h"
28 #include "chrome/common/gtk_util.h" 28 #include "chrome/common/gtk_util.h"
29 #include "chrome/common/notification_source.h" 29 #include "chrome/common/notification_source.h"
30 #include "chrome/common/notification_type.h" 30 #include "chrome/common/notification_type.h"
31 #include "webkit/api/public/WebInputEvent.h"
32
33 using WebKit::WebInputEvent;
34 using WebKit::WebMouseEvent;
31 35
32 namespace { 36 namespace {
33 37
34 // TODO(erg): I have no idea how to progromatically figure out how wide the 38 // TODO(erg): I have no idea how to progromatically figure out how wide the
35 // vertical scrollbar is. Hack it with a hardcoded value for now. 39 // vertical scrollbar is. Hack it with a hardcoded value for now.
36 const int kScrollbarWidthHack = 25; 40 const int kScrollbarWidthHack = 25;
37 41
38 // Called when the content view gtk widget is tabbed to, or after the call to 42 // Called when the content view gtk widget is tabbed to, or after the call to
39 // gtk_widget_child_focus() in TakeFocus(). We return true 43 // gtk_widget_child_focus() in TakeFocus(). We return true
40 // and grab focus if we don't have it. The call to 44 // and grab focus if we don't have it. The call to
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 105
102 // static 106 // static
103 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { 107 TabContentsView* TabContentsView::Create(TabContents* tab_contents) {
104 return new TabContentsViewGtk(tab_contents); 108 return new TabContentsViewGtk(tab_contents);
105 } 109 }
106 110
107 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) 111 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents)
108 : TabContentsView(tab_contents), 112 : TabContentsView(tab_contents),
109 floating_(gtk_floating_container_new()), 113 floating_(gtk_floating_container_new()),
110 fixed_(gtk_fixed_new()), 114 fixed_(gtk_fixed_new()),
111 popup_view_(NULL) { 115 popup_view_(NULL),
116 outstanding_clipboard_contents_request_(NULL) {
112 g_signal_connect(fixed_, "size-allocate", 117 g_signal_connect(fixed_, "size-allocate",
113 G_CALLBACK(OnSizeAllocate), this); 118 G_CALLBACK(OnSizeAllocate), this);
114 g_signal_connect(floating_.get(), "set-floating-position", 119 g_signal_connect(floating_.get(), "set-floating-position",
115 G_CALLBACK(OnSetFloatingPosition), this); 120 G_CALLBACK(OnSetFloatingPosition), this);
116 121
117 gtk_container_add(GTK_CONTAINER(floating_.get()), fixed_); 122 gtk_container_add(GTK_CONTAINER(floating_.get()), fixed_);
118 gtk_widget_show(fixed_); 123 gtk_widget_show(fixed_);
119 gtk_widget_show(floating_.get()); 124 gtk_widget_show(floating_.get());
120 registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, 125 registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED,
121 Source<TabContents>(tab_contents)); 126 Source<TabContents>(tab_contents));
122 } 127 }
123 128
124 TabContentsViewGtk::~TabContentsViewGtk() { 129 TabContentsViewGtk::~TabContentsViewGtk() {
125 floating_.Destroy(); 130 floating_.Destroy();
131 if (outstanding_clipboard_contents_request_)
132 outstanding_clipboard_contents_request_->Cancel();
126 } 133 }
127 134
128 void TabContentsViewGtk::AttachBlockedPopupView( 135 void TabContentsViewGtk::AttachBlockedPopupView(
129 BlockedPopupContainerViewGtk* popup_view) { 136 BlockedPopupContainerViewGtk* popup_view) {
130 DCHECK(popup_view_ == NULL); 137 DCHECK(popup_view_ == NULL);
131 popup_view_ = popup_view; 138 popup_view_ = popup_view;
132 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(floating_.get()), 139 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(floating_.get()),
133 popup_view->widget()); 140 popup_view->widget());
134 } 141 }
135 142
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 if (event.type == WebKit::WebInputEvent::Char) 323 if (event.type == WebKit::WebInputEvent::Char)
317 return; 324 return;
318 325
319 BrowserWindowGtk* browser_window = 326 BrowserWindowGtk* browser_window =
320 BrowserWindowGtk::GetBrowserWindowForNativeWindow(window); 327 BrowserWindowGtk::GetBrowserWindowForNativeWindow(window);
321 DCHECK(browser_window); 328 DCHECK(browser_window);
322 browser_window->HandleAccelerator(event.os_event->keyval, 329 browser_window->HandleAccelerator(event.os_event->keyval,
323 static_cast<GdkModifierType>(event.os_event->state)); 330 static_cast<GdkModifierType>(event.os_event->state));
324 } 331 }
325 332
333 TabContentsViewGtk::ClipboardRequestCallback::ClipboardRequestCallback(
334 TabContentsViewGtk* tab_contents_view)
335 : tab_contents_view_(tab_contents_view) {
336 }
337
338 void TabContentsViewGtk::ClipboardRequestCallback::Cancel() {
339 tab_contents_view_ = NULL;
340 }
341
342 void TabContentsViewGtk::ClipboardRequestCallback::Callback(
343 const gchar* utf8_string) {
344 if (tab_contents_view_)
345 tab_contents_view_->ClipboardContentsReceived(utf8_string);
346
347 delete this;
348 }
349
350 static void ClipboardCallback(GtkClipboard *clipboard,
351 const gchar *utf8_string,
352 gpointer arg) {
353 TabContentsViewGtk::ClipboardRequestCallback* callback =
354 reinterpret_cast<TabContentsViewGtk::ClipboardRequestCallback*>(arg);
355 callback->Callback(utf8_string);
356 }
357
358 void TabContentsViewGtk::HandleMouseButtonEvent(const WebMouseEvent* event) {
359 // We only trigger on middle-button up with Control held down.
360 if (event->type != WebInputEvent::MouseUp ||
361 event->button != WebMouseEvent::ButtonMiddle ||
362 (event->modifiers & WebInputEvent::ControlKey) == 0 ||
363 event->modifiers & WebInputEvent::ShiftKey ||
364 event->modifiers & WebInputEvent::AltKey ||
365 event->modifiers & WebInputEvent::MetaKey ||
366 outstanding_clipboard_contents_request_) {
367 return;
368 }
369
370 outstanding_clipboard_contents_request_ = new ClipboardRequestCallback(this);
371 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
372 gtk_clipboard_request_text(x_clipboard, ClipboardCallback,
373 outstanding_clipboard_contents_request_);
374 }
375
376 void TabContentsViewGtk::ClipboardContentsReceived(const gchar* utf8_contents) {
377 outstanding_clipboard_contents_request_ = NULL;
378 if (!utf8_contents)
379 return;
380
381 GURL target(utf8_contents);
382 if (!target.is_valid())
383 target = GURL(std::string("http://") + utf8_contents);
384 if (!target.is_valid())
385 return;
386
387 tab_contents()->RequestOpenURL(target, GURL() /* referrer */,
388 NEW_FOREGROUND_TAB);
389 }
390
326 void TabContentsViewGtk::Observe(NotificationType type, 391 void TabContentsViewGtk::Observe(NotificationType type,
327 const NotificationSource& source, 392 const NotificationSource& source,
328 const NotificationDetails& details) { 393 const NotificationDetails& details) {
329 switch (type.value) { 394 switch (type.value) {
330 case NotificationType::TAB_CONTENTS_CONNECTED: { 395 case NotificationType::TAB_CONTENTS_CONNECTED: {
331 // No need to remove the SadTabGtk's widget from the container since 396 // No need to remove the SadTabGtk's widget from the container since
332 // the new RenderWidgetHostViewGtk instance already removed all the 397 // the new RenderWidgetHostViewGtk instance already removed all the
333 // vbox's children. 398 // vbox's children.
334 sad_tab_.reset(); 399 sad_tab_.reset();
335 break; 400 break;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 499 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
435 widget, "x", &value); 500 widget, "x", &value);
436 501
437 int child_y = std::max(half_view_height - (requisition.height / 2), 0); 502 int child_y = std::max(half_view_height - (requisition.height / 2), 0);
438 g_value_set_int(&value, child_y); 503 g_value_set_int(&value, child_y);
439 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 504 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
440 widget, "y", &value); 505 widget, "y", &value);
441 g_value_unset(&value); 506 g_value_unset(&value);
442 } 507 }
443 } 508 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_view_gtk.h ('k') | chrome/browser/views/tab_contents/tab_contents_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698