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

Side by Side Diff: webkit/glue/webview_impl.cc

Issue 147246: Linux: middle-click to navigate (Closed)
Patch Set: ... Created 11 years, 5 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
« no previous file with comments | « webkit/glue/webview_impl.h ('k') | webkit/glue/webwidget_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2007 Google Inc. All Rights Reserved. 2 * Copyright 2007 Google Inc. All Rights Reserved.
3 * 3 *
4 * Portions Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 4 * Portions Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
5 * 5 *
6 * ***** BEGIN LICENSE BLOCK ***** 6 * ***** BEGIN LICENSE BLOCK *****
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 // ignore it. 423 // ignore it.
424 if (!main_frame() || !main_frame()->frameview()) 424 if (!main_frame() || !main_frame()->frameview())
425 return; 425 return;
426 426
427 delegate_->UpdateTargetURL(this, GURL()); 427 delegate_->UpdateTargetURL(this, GURL());
428 428
429 main_frame()->frame()->eventHandler()->handleMouseMoveEvent( 429 main_frame()->frame()->eventHandler()->handleMouseMoveEvent(
430 MakePlatformMouseEvent(main_frame()->frameview(), event)); 430 MakePlatformMouseEvent(main_frame()->frameview(), event));
431 } 431 }
432 432
433 void WebViewImpl::MouseDown(const WebMouseEvent& event) { 433 bool WebViewImpl::MouseDown(const WebMouseEvent& event) {
434 if (!main_frame() || !main_frame()->frameview()) 434 if (!main_frame() || !main_frame()->frameview())
435 return; 435 return false;
436 436
437 last_mouse_down_point_ = gfx::Point(event.x, event.y); 437 last_mouse_down_point_ = gfx::Point(event.x, event.y);
438 438
439 // If a text field that has focus is clicked again, we should display the 439 // If a text field that has focus is clicked again, we should display the
440 // autocomplete popup. 440 // autocomplete popup.
441 RefPtr<Node> clicked_node; 441 RefPtr<Node> clicked_node;
442 if (event.button == WebMouseEvent::ButtonLeft) { 442 if (event.button == WebMouseEvent::ButtonLeft) {
443 RefPtr<Node> focused_node = GetFocusedNode(); 443 RefPtr<Node> focused_node = GetFocusedNode();
444 if (focused_node.get() && 444 if (focused_node.get() &&
445 webkit_glue::NodeToHTMLInputElement(focused_node.get())) { 445 webkit_glue::NodeToHTMLInputElement(focused_node.get())) {
446 IntPoint point(event.x, event.y); 446 IntPoint point(event.x, event.y);
447 HitTestResult result(point); 447 HitTestResult result(point);
448 result = page_->mainFrame()->eventHandler()->hitTestResultAtPoint(point, 448 result = page_->mainFrame()->eventHandler()->hitTestResultAtPoint(point,
449 false); 449 false);
450 if (result.innerNonSharedNode() == focused_node) { 450 if (result.innerNonSharedNode() == focused_node) {
451 // Already focused text field was clicked, let's remember this. If 451 // Already focused text field was clicked, let's remember this. If
452 // focus has not changed after the mouse event is processed, we'll 452 // focus has not changed after the mouse event is processed, we'll
453 // trigger the autocomplete. 453 // trigger the autocomplete.
454 clicked_node = focused_node; 454 clicked_node = focused_node;
455 } 455 }
456 } 456 }
457 } 457 }
458 458
459 main_frame()->frame()->eventHandler()->handleMousePressEvent( 459 bool processed = main_frame()->frame()->eventHandler()->handleMousePressEvent(
460 MakePlatformMouseEvent(main_frame()->frameview(), event)); 460 MakePlatformMouseEvent(main_frame()->frameview(), event));
461 461
462 if (clicked_node.get() && clicked_node == GetFocusedNode()) { 462 if (clicked_node.get() && clicked_node == GetFocusedNode()) {
463 // Focus has not changed, show the autocomplete popup. 463 // Focus has not changed, show the autocomplete popup.
464 static_cast<EditorClientImpl*>(page_->editorClient())-> 464 static_cast<EditorClientImpl*>(page_->editorClient())->
465 ShowFormAutofillForNode(clicked_node.get()); 465 ShowFormAutofillForNode(clicked_node.get());
466 } 466 }
467 467
468 // Dispatch the contextmenu event regardless of if the click was swallowed. 468 // Dispatch the contextmenu event regardless of if the click was swallowed.
469 // On Windows, we handle it on mouse up, not down. 469 // On Windows, we handle it on mouse up, not down.
470 #if defined(OS_MACOSX) 470 #if defined(OS_MACOSX)
471 if (event.button == WebMouseEvent::ButtonRight || 471 if (event.button == WebMouseEvent::ButtonRight ||
472 (event.button == WebMouseEvent::ButtonLeft && 472 (event.button == WebMouseEvent::ButtonLeft &&
473 event.modifiers & WebMouseEvent::ControlKey)) { 473 event.modifiers & WebMouseEvent::ControlKey)) {
474 MouseContextMenu(event); 474 MouseContextMenu(event);
475 return true;
475 } 476 }
476 #elif defined(OS_LINUX) 477 #elif defined(OS_LINUX)
477 if (event.button == WebMouseEvent::ButtonRight) 478 if (event.button == WebMouseEvent::ButtonRight) {
478 MouseContextMenu(event); 479 MouseContextMenu(event);
480 return true;
481 }
479 #endif 482 #endif
483
484 return processed;
480 } 485 }
481 486
482 void WebViewImpl::MouseContextMenu(const WebMouseEvent& event) { 487 void WebViewImpl::MouseContextMenu(const WebMouseEvent& event) {
483 if (!main_frame() || !main_frame()->frameview()) 488 if (!main_frame() || !main_frame()->frameview())
484 return; 489 return;
485 490
486 page_->contextMenuController()->clearContextMenu(); 491 page_->contextMenuController()->clearContextMenu();
487 492
488 MakePlatformMouseEvent pme(main_frame()->frameview(), event); 493 MakePlatformMouseEvent pme(main_frame()->frameview(), event);
489 494
490 // Find the right target frame. See issue 1186900. 495 // Find the right target frame. See issue 1186900.
491 HitTestResult result = HitTestResultForWindowPos(pme.pos()); 496 HitTestResult result = HitTestResultForWindowPos(pme.pos());
492 Frame* target_frame; 497 Frame* target_frame;
493 if (result.innerNonSharedNode()) 498 if (result.innerNonSharedNode())
494 target_frame = result.innerNonSharedNode()->document()->frame(); 499 target_frame = result.innerNonSharedNode()->document()->frame();
495 else 500 else
496 target_frame = page_->focusController()->focusedOrMainFrame(); 501 target_frame = page_->focusController()->focusedOrMainFrame();
497 502
498 #if defined(OS_WIN) 503 #if defined(OS_WIN)
499 target_frame->view()->setCursor(pointerCursor()); 504 target_frame->view()->setCursor(pointerCursor());
500 #endif 505 #endif
501 506
502 context_menu_allowed_ = true; 507 context_menu_allowed_ = true;
503 target_frame->eventHandler()->sendContextMenuEvent(pme); 508 target_frame->eventHandler()->sendContextMenuEvent(pme);
504 context_menu_allowed_ = false; 509 context_menu_allowed_ = false;
505 // Actually showing the context menu is handled by the ContextMenuClient 510 // Actually showing the context menu is handled by the ContextMenuClient
506 // implementation... 511 // implementation...
507 } 512 }
508 513
509 void WebViewImpl::MouseUp(const WebMouseEvent& event) { 514 bool WebViewImpl::MouseUp(const WebMouseEvent& event) {
510 if (!main_frame() || !main_frame()->frameview()) 515 if (!main_frame() || !main_frame()->frameview())
511 return; 516 return false;
512 517
513 MouseCaptureLost(); 518 MouseCaptureLost();
514 main_frame()->frame()->eventHandler()->handleMouseReleaseEvent( 519 bool processed =
515 MakePlatformMouseEvent(main_frame()->frameview(), event)); 520 main_frame()->frame()->eventHandler()->handleMouseReleaseEvent(
521 MakePlatformMouseEvent(main_frame()->frameview(), event));
516 522
517 #if defined(OS_WIN) 523 #if defined(OS_WIN)
518 // Dispatch the contextmenu event regardless of if the click was swallowed. 524 // Dispatch the contextmenu event regardless of if the click was swallowed.
519 // On Mac/Linux, we handle it on mouse down, not up. 525 // On Mac/Linux, we handle it on mouse down, not up.
520 if (event.button == WebMouseEvent::ButtonRight) 526 if (event.button == WebMouseEvent::ButtonRight) {
521 MouseContextMenu(event); 527 MouseContextMenu(event);
528 return true;
529 }
522 #endif 530 #endif
523 531
524 #if defined(OS_LINUX) 532 #if defined(OS_LINUX)
525 // If the event was a middle click, attempt to copy text into the focused 533 // If the event was a middle click, attempt to copy text into the focused
526 // frame. 534 // frame.
527 // 535 //
528 // This code is in the mouse up handler. There is some debate about putting 536 // This code is in the mouse up handler. There is some debate about putting
529 // this here, as opposed to the mouse down handler. 537 // this here, as opposed to the mouse down handler.
530 // xterm: pastes on up. 538 // xterm: pastes on up.
531 // GTK: pastes on down. 539 // GTK: pastes on down.
532 // Firefox: pastes on up. 540 // Firefox: pastes on up.
533 // Midori: couldn't paste at all with 0.1.2 541 // Midori: couldn't paste at all with 0.1.2
534 // 542 //
535 // There is something of a webcompat angle to this well, as highlighted by 543 // There is something of a webcompat angle to this well, as highlighted by
536 // crbug.com/14608. Pages can clear text boxes 'onclick' and, if we paste on 544 // crbug.com/14608. Pages can clear text boxes 'onclick' and, if we paste on
537 // down then the text is pasted just before the onclick handler runs and 545 // down then the text is pasted just before the onclick handler runs and
538 // clears the text box. So it's important this happens after the 546 // clears the text box. So it's important this happens after the
539 // handleMouseReleaseEvent() earlier in this function 547 // handleMouseReleaseEvent() earlier in this function
540 if (event.button == WebMouseEvent::ButtonMiddle) { 548 if (event.button == WebMouseEvent::ButtonMiddle) {
541 Frame* focused = GetFocusedWebCoreFrame(); 549 Frame* focused = GetFocusedWebCoreFrame();
542 if (!focused) 550 if (!focused)
543 return; 551 return processed;
544 Editor* editor = focused->editor(); 552 Editor* editor = focused->editor();
545 if (!editor || !editor->canEdit()) 553 if (!editor || !editor->canEdit())
546 return; 554 return processed;
547 555
548 delegate_->PasteFromSelectionClipboard(); 556 delegate_->PasteFromSelectionClipboard();
557 return true;
549 } 558 }
550 #endif 559 #endif
560
561 return processed;
551 } 562 }
552 563
553 void WebViewImpl::MouseWheel(const WebMouseWheelEvent& event) { 564 void WebViewImpl::MouseWheel(const WebMouseWheelEvent& event) {
554 MakePlatformWheelEvent platform_event(main_frame()->frameview(), event); 565 MakePlatformWheelEvent platform_event(main_frame()->frameview(), event);
555 main_frame()->frame()->eventHandler()->handleWheelEvent(platform_event); 566 main_frame()->frame()->eventHandler()->handleWheelEvent(platform_event);
556 } 567 }
557 568
558 bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) { 569 bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) {
559 DCHECK((event.type == WebInputEvent::RawKeyDown) || 570 DCHECK((event.type == WebInputEvent::RawKeyDown) ||
560 (event.type == WebInputEvent::KeyDown) || 571 (event.type == WebInputEvent::KeyDown) ||
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 1063
1053 case WebInputEvent::MouseLeave: 1064 case WebInputEvent::MouseLeave:
1054 MouseLeave(*static_cast<const WebMouseEvent*>(input_event)); 1065 MouseLeave(*static_cast<const WebMouseEvent*>(input_event));
1055 break; 1066 break;
1056 1067
1057 case WebInputEvent::MouseWheel: 1068 case WebInputEvent::MouseWheel:
1058 MouseWheel(*static_cast<const WebMouseWheelEvent*>(input_event)); 1069 MouseWheel(*static_cast<const WebMouseWheelEvent*>(input_event));
1059 break; 1070 break;
1060 1071
1061 case WebInputEvent::MouseDown: 1072 case WebInputEvent::MouseDown:
1062 MouseDown(*static_cast<const WebMouseEvent*>(input_event)); 1073 return MouseDown(*static_cast<const WebMouseEvent*>(input_event));
1063 break;
1064 1074
1065 case WebInputEvent::MouseUp: 1075 case WebInputEvent::MouseUp:
1066 MouseUp(*static_cast<const WebMouseEvent*>(input_event)); 1076 return MouseUp(*static_cast<const WebMouseEvent*>(input_event));
1067 break;
1068 1077
1069 case WebInputEvent::RawKeyDown: 1078 case WebInputEvent::RawKeyDown:
1070 case WebInputEvent::KeyDown: 1079 case WebInputEvent::KeyDown:
1071 case WebInputEvent::KeyUp: 1080 case WebInputEvent::KeyUp:
1072 handled = KeyEvent(*static_cast<const WebKeyboardEvent*>(input_event)); 1081 handled = KeyEvent(*static_cast<const WebKeyboardEvent*>(input_event));
1073 break; 1082 break;
1074 1083
1075 case WebInputEvent::Char: 1084 case WebInputEvent::Char:
1076 handled = CharEvent(*static_cast<const WebKeyboardEvent*>(input_event)); 1085 handled = CharEvent(*static_cast<const WebKeyboardEvent*>(input_event));
1077 break; 1086 break;
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 1950
1942 return document->focusedNode(); 1951 return document->focusedNode();
1943 } 1952 }
1944 1953
1945 HitTestResult WebViewImpl::HitTestResultForWindowPos(const IntPoint& pos) { 1954 HitTestResult WebViewImpl::HitTestResultForWindowPos(const IntPoint& pos) {
1946 IntPoint doc_point( 1955 IntPoint doc_point(
1947 page_->mainFrame()->view()->windowToContents(pos)); 1956 page_->mainFrame()->view()->windowToContents(pos));
1948 return page_->mainFrame()->eventHandler()-> 1957 return page_->mainFrame()->eventHandler()->
1949 hitTestResultAtPoint(doc_point, false); 1958 hitTestResultAtPoint(doc_point, false);
1950 } 1959 }
OLDNEW
« no previous file with comments | « webkit/glue/webview_impl.h ('k') | webkit/glue/webwidget_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698