-
Notifications
You must be signed in to change notification settings - Fork 901
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3687 from brave/maxk-fix-hover-card-bubble-2
Fixes hover card bubble chrome:// urls.
- Loading branch information
Showing
5 changed files
with
230 additions
and
10 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
chromium_src/chrome/browser/ui/views/tabs/tab_hover_card_bubble_view.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* Copyright (c) 2019 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* you can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include <string> | ||
|
||
#include "base/strings/string_util.h" | ||
#include "base/strings/utf_string_conversions.h" | ||
#include "chrome/browser/ui/views/tabs/tab.h" | ||
#include "chrome/browser/ui/views/tabs/tab_hover_card_bubble_view.h" | ||
#include "content/public/common/url_constants.h" | ||
#include "ui/views/controls/label.h" | ||
|
||
#define TabHoverCardBubbleView TabHoverCardBubbleView_ChromiumImpl | ||
#include "../../../../../../chrome/browser/ui/views/tabs/tab_hover_card_bubble_view.cc" | ||
#undef TabHoverCardBubbleView | ||
|
||
void TabHoverCardBubbleView_ChromiumImpl::BraveUpdateCardContent( | ||
const Tab* tab) { | ||
TabHoverCardBubbleView_ChromiumImpl::UpdateCardContent(tab); | ||
const base::string16& domain = domain_label_->GetText(); | ||
const base::string16 kChromeUISchemeU16 = | ||
base::ASCIIToUTF16(content::kChromeUIScheme); | ||
// Replace chrome:// with brave://. Since this is purely in the UI we can | ||
// just do a sub-string replacement instead of parsing into GURL. | ||
if (base::StartsWith(domain, kChromeUISchemeU16, | ||
base::CompareCase::INSENSITIVE_ASCII)) { | ||
base::string16 new_domain = domain; | ||
base::ReplaceFirstSubstringAfterOffset( | ||
&new_domain, 0ul, kChromeUISchemeU16, | ||
base::ASCIIToUTF16(content::kBraveUIScheme)); | ||
domain_label_->SetText(new_domain); | ||
} | ||
} | ||
|
||
void TabHoverCardBubbleView::UpdateCardContent(const Tab* tab) { | ||
BraveUpdateCardContent(tab); | ||
} |
33 changes: 33 additions & 0 deletions
33
chromium_src/chrome/browser/ui/views/tabs/tab_hover_card_bubble_view.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* Copyright (c) 2019 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* you can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TABS_TAB_HOVER_CARD_BUBBLE_VIEW_H_ | ||
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TABS_TAB_HOVER_CARD_BUBBLE_VIEW_H_ | ||
|
||
// Inject a protected method that will have access to the private members of the | ||
// base class. Then, we can call this method from the subclass' override. | ||
#define BRAVE_TAB_HOVER_CARD_BUBBLE_VIEW_H_ \ | ||
protected: \ | ||
void BraveUpdateCardContent(const Tab* tab); | ||
|
||
#define TabHoverCardBubbleView TabHoverCardBubbleView_ChromiumImpl | ||
#define UpdateCardContent virtual UpdateCardContent | ||
#include "../../../../../../chrome/browser/ui/views/tabs/tab_hover_card_bubble_view.h" | ||
#undef UpdateCardContent | ||
#undef TabHoverCardBubbleView | ||
#undef BRAVE_TAB_HOVER_CARD_BUBBLE_VIEW_H_ | ||
|
||
class TabHoverCardBubbleView : public TabHoverCardBubbleView_ChromiumImpl { | ||
public: | ||
using TabHoverCardBubbleView_ChromiumImpl:: | ||
TabHoverCardBubbleView_ChromiumImpl; | ||
|
||
private: | ||
void UpdateCardContent(const Tab* tab) override; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(TabHoverCardBubbleView); | ||
}; | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TABS_TAB_HOVER_CARD_BUBBLE_VIEW_H_ |
129 changes: 129 additions & 0 deletions
129
chromium_src/chrome/browser/ui/views/tabs/tab_hover_card_bubble_view_browsertest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* Copyright (c) 2019 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "base/strings/string_util.h" | ||
#include "base/test/scoped_feature_list.h" | ||
#include "chrome/browser/ui/test/test_browser_dialog.h" | ||
#include "chrome/browser/ui/ui_features.h" | ||
#include "chrome/browser/ui/views/tabs/tab_hover_card_bubble_view.h" | ||
#include "chrome/browser/ui/views/tabs/tab_strip.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "chrome/test/base/ui_test_utils.h" | ||
#include "ui/gfx/animation/animation_test_api.h" | ||
#include "ui/views/controls/label.h" | ||
#include "ui/views/widget/widget.h" | ||
#include "ui/views/widget/widget_observer.h" | ||
|
||
using views::Widget; | ||
|
||
// Helper to wait until the hover card widget is visible. | ||
class HoverCardVisibleWaiter : public views::WidgetObserver { | ||
public: | ||
explicit HoverCardVisibleWaiter(Widget* hover_card) | ||
: hover_card_(hover_card) { | ||
hover_card_->AddObserver(this); | ||
} | ||
~HoverCardVisibleWaiter() override { hover_card_->RemoveObserver(this); } | ||
|
||
void Wait() { | ||
if (hover_card_->IsVisible()) | ||
return; | ||
run_loop_.Run(); | ||
} | ||
|
||
// WidgetObserver overrides: | ||
void OnWidgetVisibilityChanged(Widget* widget, bool visible) override { | ||
if (visible) | ||
run_loop_.Quit(); | ||
} | ||
|
||
private: | ||
Widget* const hover_card_; | ||
base::RunLoop run_loop_; | ||
}; | ||
|
||
class TabHoverCardBubbleViewBrowserTest : public DialogBrowserTest { | ||
public: | ||
TabHoverCardBubbleViewBrowserTest() | ||
: animation_mode_reset_(gfx::AnimationTestApi::SetRichAnimationRenderMode( | ||
gfx::Animation::RichAnimationRenderMode::FORCE_DISABLED)) { | ||
TabHoverCardBubbleView::disable_animations_for_testing_ = true; | ||
} | ||
~TabHoverCardBubbleViewBrowserTest() override = default; | ||
|
||
void SetUp() override { | ||
scoped_feature_list_.InitAndEnableFeature(features::kTabHoverCards); | ||
DialogBrowserTest::SetUp(); | ||
} | ||
|
||
static TabHoverCardBubbleView* GetHoverCard(const TabStrip* tabstrip) { | ||
return tabstrip->hover_card_; | ||
} | ||
|
||
static Widget* GetHoverCardWidget(const TabHoverCardBubbleView* hover_card) { | ||
return hover_card->widget_; | ||
} | ||
|
||
const base::string16& GetHoverCardTitle( | ||
const TabHoverCardBubbleView* hover_card) { | ||
return hover_card->title_label_->GetText(); | ||
} | ||
|
||
const base::string16& GetHoverCardDomain( | ||
const TabHoverCardBubbleView* hover_card) { | ||
return hover_card->domain_label_->GetText(); | ||
} | ||
|
||
void HoverMouseOverTabAt(int index) { | ||
TabStrip* tab_strip = | ||
BrowserView::GetBrowserViewForBrowser(browser())->tabstrip(); | ||
Tab* tab = tab_strip->tab_at(index); | ||
ui::MouseEvent hover_event(ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(), | ||
base::TimeTicks(), ui::EF_NONE, 0); | ||
tab->OnMouseEntered(hover_event); | ||
} | ||
|
||
// DialogBrowserTest: | ||
void ShowUi(const std::string& name) override { | ||
TabStrip* tab_strip = | ||
BrowserView::GetBrowserViewForBrowser(browser())->tabstrip(); | ||
Tab* tab = tab_strip->tab_at(0); | ||
ui::MouseEvent hover_event(ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(), | ||
base::TimeTicks(), ui::EF_NONE, 0); | ||
tab->OnMouseEntered(hover_event); | ||
TabHoverCardBubbleView* hover_card = GetHoverCard(tab_strip); | ||
Widget* widget = GetHoverCardWidget(hover_card); | ||
HoverCardVisibleWaiter waiter(widget); | ||
waiter.Wait(); | ||
} | ||
|
||
private: | ||
std::unique_ptr<base::AutoReset<gfx::Animation::RichAnimationRenderMode>> | ||
animation_mode_reset_; | ||
base::test::ScopedFeatureList scoped_feature_list_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(TabHoverCardBubbleViewBrowserTest); | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(TabHoverCardBubbleViewBrowserTest, ChromeSchemeUrl) { | ||
TabStrip* tab_strip = | ||
BrowserView::GetBrowserViewForBrowser(browser())->tabstrip(); | ||
TabRendererData new_tab_data = TabRendererData(); | ||
new_tab_data.title = base::UTF8ToUTF16("Settings - Addresses and more"); | ||
new_tab_data.last_committed_url = | ||
GURL("chrome://settings/addresses"); | ||
tab_strip->AddTabAt(1, new_tab_data, false); | ||
|
||
ShowUi("default"); | ||
TabHoverCardBubbleView* hover_card = GetHoverCard(tab_strip); | ||
Widget* widget = GetHoverCardWidget(hover_card); | ||
EXPECT_TRUE(widget != nullptr); | ||
EXPECT_TRUE(widget->IsVisible()); | ||
HoverMouseOverTabAt(1); | ||
EXPECT_EQ(GetHoverCardTitle(hover_card), | ||
base::UTF8ToUTF16("Settings - Addresses and more")); | ||
EXPECT_EQ(GetHoverCardDomain(hover_card), | ||
base::UTF8ToUTF16("brave://settings")); | ||
} |
12 changes: 12 additions & 0 deletions
12
patches/chrome-browser-ui-views-tabs-tab_hover_card_bubble_view.h.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
diff --git a/chrome/browser/ui/views/tabs/tab_hover_card_bubble_view.h b/chrome/browser/ui/views/tabs/tab_hover_card_bubble_view.h | ||
index eaa40d8fdb646fe7ae39a2f363b3e8405519509b..b600a7bd9908b20bef9c42fcd18a83f838d42ec8 100644 | ||
--- a/chrome/browser/ui/views/tabs/tab_hover_card_bubble_view.h | ||
+++ b/chrome/browser/ui/views/tabs/tab_hover_card_bubble_view.h | ||
@@ -61,6 +61,7 @@ class TabHoverCardBubbleView : public views::BubbleDialogDelegateView, | ||
last_mouse_exit_timestamp_ = last_mouse_exit_timestamp; | ||
} | ||
|
||
+ BRAVE_TAB_HOVER_CARD_BUBBLE_VIEW_H_ | ||
private: | ||
friend class TabHoverCardBubbleViewBrowserTest; | ||
friend class TabHoverCardBubbleViewInteractiveUiTest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters