summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-15 23:42:16 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-15 23:42:16 +0000
commit73765a778fae775afa42f35511e4a4922d87dfc1 (patch)
treecc79e66fa0dd27a57a8a09c890068ebb764c8b4b /chrome/browser/ui
parent0eafc096894e1f219a8f71572bf0e5b85fabf17b (diff)
downloadchromium_src-73765a778fae775afa42f35511e4a4922d87dfc1.zip
chromium_src-73765a778fae775afa42f35511e4a4922d87dfc1.tar.gz
chromium_src-73765a778fae775afa42f35511e4a4922d87dfc1.tar.bz2
linux-aura: Restore middle-click on new-tab button behaviour.
Middle-clicking on new-tab button opens a new tab and navigates to the URL in the clipboard, or navigates to the search-result page for the clipboard content if it's not a URL. BUG=319011 R=sky@chromium.org Review URL: https://codereview.chromium.org/74133003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235469 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r--chrome/browser/ui/browser_tab_strip_model_delegate.cc6
-rw-r--r--chrome/browser/ui/browser_tab_strip_model_delegate.h6
-rw-r--r--chrome/browser/ui/browser_tabstrip.cc13
-rw-r--r--chrome/browser/ui/browser_tabstrip.h5
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm2
-rw-r--r--chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc2
-rw-r--r--chrome/browser/ui/tabs/tab_strip_model.cc2
-rw-r--r--chrome/browser/ui/tabs/tab_strip_model_delegate.h8
-rw-r--r--chrome/browser/ui/tabs/test_tab_strip_model_delegate.cc4
-rw-r--r--chrome/browser/ui/tabs/test_tab_strip_model_delegate.h2
-rw-r--r--chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc16
-rw-r--r--chrome/browser/ui/views/tabs/browser_tab_strip_controller.h1
-rw-r--r--chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.cc4
-rw-r--r--chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h1
-rw-r--r--chrome/browser/ui/views/tabs/tab_strip.cc24
-rw-r--r--chrome/browser/ui/views/tabs/tab_strip_controller.h6
16 files changed, 86 insertions, 16 deletions
diff --git a/chrome/browser/ui/browser_tab_strip_model_delegate.cc b/chrome/browser/ui/browser_tab_strip_model_delegate.cc
index 43a8d51..d794320 100644
--- a/chrome/browser/ui/browser_tab_strip_model_delegate.cc
+++ b/chrome/browser/ui/browser_tab_strip_model_delegate.cc
@@ -39,8 +39,10 @@ BrowserTabStripModelDelegate::~BrowserTabStripModelDelegate() {
////////////////////////////////////////////////////////////////////////////////
// BrowserTabStripModelDelegate, TabStripModelDelegate implementation:
-void BrowserTabStripModelDelegate::AddBlankTabAt(int index, bool foreground) {
- chrome::AddBlankTabAt(browser_, index, foreground);
+void BrowserTabStripModelDelegate::AddURLTabAt(const GURL& url,
+ int index,
+ bool foreground) {
+ chrome::AddURLTabAt(browser_, url, index, foreground);
}
Browser* BrowserTabStripModelDelegate::CreateNewStripWithContents(
diff --git a/chrome/browser/ui/browser_tab_strip_model_delegate.h b/chrome/browser/ui/browser_tab_strip_model_delegate.h
index 405c01f..798ce98 100644
--- a/chrome/browser/ui/browser_tab_strip_model_delegate.h
+++ b/chrome/browser/ui/browser_tab_strip_model_delegate.h
@@ -9,6 +9,8 @@
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
+class GURL;
+
namespace chrome {
class BrowserTabStripModelDelegate : public TabStripModelDelegate {
@@ -18,7 +20,9 @@ class BrowserTabStripModelDelegate : public TabStripModelDelegate {
private:
// Overridden from TabStripModelDelegate:
- virtual void AddBlankTabAt(int index, bool foreground) OVERRIDE;
+ virtual void AddURLTabAt(const GURL& url,
+ int index,
+ bool foreground) OVERRIDE;
virtual Browser* CreateNewStripWithContents(
const std::vector<NewStripContents>& contentses,
const gfx::Rect& window_bounds,
diff --git a/chrome/browser/ui/browser_tabstrip.cc b/chrome/browser/ui/browser_tabstrip.cc
index ba95d58..d0bee66 100644
--- a/chrome/browser/ui/browser_tabstrip.cc
+++ b/chrome/browser/ui/browser_tabstrip.cc
@@ -18,21 +18,26 @@
namespace chrome {
-void AddBlankTabAt(Browser* browser, int index, bool foreground) {
+void AddURLTabAt(Browser* browser, const GURL& url, int idx, bool foreground) {
// Time new tab page creation time. We keep track of the timing data in
// WebContents, but we want to include the time it takes to create the
// WebContents object too.
base::TimeTicks new_tab_start_time = base::TimeTicks::Now();
- chrome::NavigateParams params(browser, GURL(chrome::kChromeUINewTabURL),
- content::PAGE_TRANSITION_TYPED);
+ chrome::NavigateParams params(browser,
+ url.is_empty() ? GURL(chrome::kChromeUINewTabURL) : url,
+ content::PAGE_TRANSITION_TYPED);
params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB;
- params.tabstrip_index = index;
+ params.tabstrip_index = idx;
chrome::Navigate(&params);
CoreTabHelper* core_tab_helper =
CoreTabHelper::FromWebContents(params.target_contents);
core_tab_helper->set_new_tab_start_time(new_tab_start_time);
}
+void AddBlankTabAt(Browser* browser, int index, bool foreground) {
+ AddURLTabAt(browser, GURL(), index, foreground);
+}
+
content::WebContents* AddSelectedTabWithURL(
Browser* browser,
const GURL& url,
diff --git a/chrome/browser/ui/browser_tabstrip.h b/chrome/browser/ui/browser_tabstrip.h
index 29612e9..a13699d 100644
--- a/chrome/browser/ui/browser_tabstrip.h
+++ b/chrome/browser/ui/browser_tabstrip.h
@@ -24,6 +24,11 @@ class Rect;
namespace chrome {
+// Adds a tab to the tab strip of the specified browser and loads |url| into it.
+// If |url| is an empty URL, then the new tab-page is laoded. An |index| of -1
+// means to append it to the end of the tab strip.
+void AddURLTabAt(Browser* browser, const GURL& url, int index, bool foreground);
+
// Adds a blank tab to the tab strip of the specified browser; an |index| of -1
// means to append it to the end of the tab strip.
void AddBlankTabAt(Browser* browser, int index, bool foreground);
diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
index b98dc32..55c26f9 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
+++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
@@ -675,7 +675,7 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) {
content::RecordAction(UserMetricsAction("NewTab_Button"));
UMA_HISTOGRAM_ENUMERATION("Tab.NewTab", TabStripModel::NEW_TAB_BUTTON,
TabStripModel::NEW_TAB_ENUM_COUNT);
- tabStripModel_->delegate()->AddBlankTabAt(-1, true);
+ tabStripModel_->delegate()->AddURLTabAt(GURL(), -1, true);
}
// (Private) Returns the number of open tabs in the tab strip. This is the
diff --git a/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc
index 9603427..cd69607 100644
--- a/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc
+++ b/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc
@@ -2185,7 +2185,7 @@ void TabStripGtk::OnNewTabClicked(GtkWidget* widget) {
content::RecordAction(UserMetricsAction("NewTab_Button"));
UMA_HISTOGRAM_ENUMERATION("Tab.NewTab", TabStripModel::NEW_TAB_BUTTON,
TabStripModel::NEW_TAB_ENUM_COUNT);
- model_->delegate()->AddBlankTabAt(-1, true);
+ model_->delegate()->AddURLTabAt(GURL(), -1, true);
break;
case 2: {
// On middle-click, try to parse the PRIMARY selection as a URL and load
diff --git a/chrome/browser/ui/tabs/tab_strip_model.cc b/chrome/browser/ui/tabs/tab_strip_model.cc
index f590dad..abb99cf 100644
--- a/chrome/browser/ui/tabs/tab_strip_model.cc
+++ b/chrome/browser/ui/tabs/tab_strip_model.cc
@@ -944,7 +944,7 @@ void TabStripModel::ExecuteContextMenuCommand(
UMA_HISTOGRAM_ENUMERATION("Tab.NewTab",
TabStripModel::NEW_TAB_CONTEXT_MENU,
TabStripModel::NEW_TAB_ENUM_COUNT);
- delegate()->AddBlankTabAt(context_index + 1, true);
+ delegate()->AddURLTabAt(GURL(), context_index + 1, true);
break;
case CommandReload: {
diff --git a/chrome/browser/ui/tabs/tab_strip_model_delegate.h b/chrome/browser/ui/tabs/tab_strip_model_delegate.h
index cc2f7d2..d3f78f0 100644
--- a/chrome/browser/ui/tabs/tab_strip_model_delegate.h
+++ b/chrome/browser/ui/tabs/tab_strip_model_delegate.h
@@ -11,6 +11,7 @@
class Browser;
class DockInfo;
+class GURL;
namespace content {
class WebContents;
@@ -47,9 +48,10 @@ class TabStripModelDelegate {
virtual ~TabStripModelDelegate() {}
- // Adds what the delegate considers to be a blank tab to the model. An |index|
- // value of -1 means to append the contents to the end of the tab strip.
- virtual void AddBlankTabAt(int index, bool foreground) = 0;
+ // Adds a tab to the model and loads |url| in the tab. If |url| is an empty
+ // URL, then the new tab-page is loaded instead. An |index| value of -1
+ // means to append the contents to the end of the tab strip.
+ virtual void AddURLTabAt(const GURL& url, int index, bool foreground) = 0;
// Asks for a new TabStripModel to be created and the given web contentses to
// be added to it. Its size and position are reflected in |window_bounds|.
diff --git a/chrome/browser/ui/tabs/test_tab_strip_model_delegate.cc b/chrome/browser/ui/tabs/test_tab_strip_model_delegate.cc
index f0037a1..b3f6eed 100644
--- a/chrome/browser/ui/tabs/test_tab_strip_model_delegate.cc
+++ b/chrome/browser/ui/tabs/test_tab_strip_model_delegate.cc
@@ -13,7 +13,9 @@ TestTabStripModelDelegate::TestTabStripModelDelegate() {
TestTabStripModelDelegate::~TestTabStripModelDelegate() {
}
-void TestTabStripModelDelegate::AddBlankTabAt(int index, bool foreground) {
+void TestTabStripModelDelegate::AddURLTabAt(const GURL& url,
+ int index,
+ bool foreground) {
}
Browser* TestTabStripModelDelegate::CreateNewStripWithContents(
diff --git a/chrome/browser/ui/tabs/test_tab_strip_model_delegate.h b/chrome/browser/ui/tabs/test_tab_strip_model_delegate.h
index a470168..3f35853 100644
--- a/chrome/browser/ui/tabs/test_tab_strip_model_delegate.h
+++ b/chrome/browser/ui/tabs/test_tab_strip_model_delegate.h
@@ -16,7 +16,7 @@ class TestTabStripModelDelegate : public TabStripModelDelegate {
virtual ~TestTabStripModelDelegate();
// Overridden from TabStripModelDelegate:
- virtual void AddBlankTabAt(int index, bool foreground) OVERRIDE;
+ virtual void AddURLTabAt(const GURL& url, int index, bool foregroud) OVERRIDE;
virtual Browser* CreateNewStripWithContents(
const std::vector<NewStripContents>& contentses,
const gfx::Rect& window_bounds,
diff --git a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc
index b495dde..f0c4050 100644
--- a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc
+++ b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc
@@ -7,6 +7,9 @@
#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/prefs/pref_service.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/tab_helper.h"
@@ -350,7 +353,18 @@ bool BrowserTabStripController::IsCompatibleWith(TabStrip* other) const {
}
void BrowserTabStripController::CreateNewTab() {
- model_->delegate()->AddBlankTabAt(-1, true);
+ model_->delegate()->AddURLTabAt(GURL(), -1, true);
+}
+
+void BrowserTabStripController::CreateNewTabWithLocation(
+ const base::string16& location) {
+ // Use autocomplete to clean up the text, going so far as to turn it into
+ // a search query if necessary.
+ AutocompleteMatch match;
+ AutocompleteClassifierFactory::GetForProfile(profile())->Classify(
+ location, false, false, &match, NULL);
+ if (match.destination_url.is_valid())
+ model_->delegate()->AddURLTabAt(match.destination_url, -1, true);
}
bool BrowserTabStripController::IsIncognito() {
diff --git a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h
index 62e5f8f..06da492 100644
--- a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h
+++ b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h
@@ -69,6 +69,7 @@ class BrowserTabStripController : public TabStripController,
const GURL& url) OVERRIDE;
virtual bool IsCompatibleWith(TabStrip* other) const OVERRIDE;
virtual void CreateNewTab() OVERRIDE;
+ virtual void CreateNewTabWithLocation(const base::string16& loc) OVERRIDE;
virtual bool IsIncognito() OVERRIDE;
virtual void LayoutTypeMaybeChanged() OVERRIDE;
virtual void OnStartedDraggingTabs() OVERRIDE;
diff --git a/chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.cc b/chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.cc
index 4100601..2ac9e82d 100644
--- a/chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.cc
+++ b/chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.cc
@@ -108,6 +108,10 @@ bool FakeBaseTabStripController::IsCompatibleWith(TabStrip* other) const {
void FakeBaseTabStripController::CreateNewTab() {
}
+void FakeBaseTabStripController::CreateNewTabWithLocation(
+ const base::string16& location) {
+}
+
bool FakeBaseTabStripController::IsIncognito() {
return false;
}
diff --git a/chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h b/chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h
index 12d4fa6..68a4b39 100644
--- a/chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h
+++ b/chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h
@@ -46,6 +46,7 @@ class FakeBaseTabStripController : public TabStripController {
const GURL& url) OVERRIDE;
virtual bool IsCompatibleWith(TabStrip* other) const OVERRIDE;
virtual void CreateNewTab() OVERRIDE;
+ virtual void CreateNewTabWithLocation(const base::string16& loc) OVERRIDE;
virtual bool IsIncognito() OVERRIDE;
virtual void LayoutTypeMaybeChanged() OVERRIDE;
virtual void OnStartedDraggingTabs() OVERRIDE;
diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc
index 8a63d2b..6491f41 100644
--- a/chrome/browser/ui/views/tabs/tab_strip.cc
+++ b/chrome/browser/ui/views/tabs/tab_strip.cc
@@ -239,6 +239,16 @@ int stacked_tab_right_clip() {
return value;
}
+base::string16 GetClipboardText() {
+ if (!ui::Clipboard::IsSupportedClipboardType(ui::CLIPBOARD_TYPE_SELECTION))
+ return base::string16();
+ ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
+ CHECK(clipboard);
+ base::string16 clipboard_text;
+ clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &clipboard_text);
+ return clipboard_text;
+}
+
// Animation delegate used when a dragged tab is released. When done sets the
// dragging state to false.
class ResetDraggingStateDelegate
@@ -346,6 +356,10 @@ NewTabButton::NewTabButton(TabStrip* tab_strip, views::ButtonListener* listener)
: views::ImageButton(listener),
tab_strip_(tab_strip),
destroyed_(NULL) {
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+ set_triggerable_event_flags(triggerable_event_flags() |
+ ui::EF_MIDDLE_MOUSE_BUTTON);
+#endif
}
NewTabButton::~NewTabButton() {
@@ -1511,6 +1525,16 @@ void TabStrip::ButtonPressed(views::Button* sender, const ui::Event& event) {
content::RecordAction(UserMetricsAction("NewTab_Button"));
UMA_HISTOGRAM_ENUMERATION("Tab.NewTab", TabStripModel::NEW_TAB_BUTTON,
TabStripModel::NEW_TAB_ENUM_COUNT);
+ if (event.IsMouseEvent()) {
+ const ui::MouseEvent& mouse = static_cast<const ui::MouseEvent&>(event);
+ if (mouse.IsOnlyMiddleMouseButton()) {
+ base::string16 clipboard_text = GetClipboardText();
+ if (!clipboard_text.empty())
+ controller()->CreateNewTabWithLocation(clipboard_text);
+ return;
+ }
+ }
+
controller()->CreateNewTab();
if (event.type() == ui::ET_GESTURE_TAP)
TouchUMA::RecordGestureAction(TouchUMA::GESTURE_NEWTAB_TAP);
diff --git a/chrome/browser/ui/views/tabs/tab_strip_controller.h b/chrome/browser/ui/views/tabs/tab_strip_controller.h
index 4e53c1b..afe7a23 100644
--- a/chrome/browser/ui/views/tabs/tab_strip_controller.h
+++ b/chrome/browser/ui/views/tabs/tab_strip_controller.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_UI_VIEWS_TABS_TAB_STRIP_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_TABS_TAB_STRIP_CONTROLLER_H_
+#include "base/strings/string16.h"
#include "chrome/browser/ui/views/tabs/tab_strip_types.h"
#include "ui/base/ui_base_types.h"
@@ -93,6 +94,11 @@ class TabStripController {
// Creates the new tab.
virtual void CreateNewTab() = 0;
+ // Creates a new tab, and loads |location| in the tab. If |location| is a
+ // valid URL, then simply loads the URL, otherwise this can open a
+ // search-result page for |location|.
+ virtual void CreateNewTabWithLocation(const base::string16& location) = 0;
+
// Returns true if the tab strip is in an incognito window.
virtual bool IsIncognito() = 0;