Skip to content

Commit

Permalink
Remove duplicated separator in page context menu
Browse files Browse the repository at this point in the history
fixes brave/brave-browser#15714

Override of RenderViewContextMenuViews::Show is used
  • Loading branch information
AlexeyBarabash committed Jun 16, 2021
1 parent 6fd2784 commit 702d950
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
7 changes: 7 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ source_set("ui") {
"views/toolbar/bookmark_button.h",
]

if (use_aura) {
sources += [
"views/renderer_context_menu/brave_render_view_context_menu_views.cc",
"views/renderer_context_menu/brave_render_view_context_menu_views.h",
]
}

if (enable_sparkle) {
sources += [
"views/update_recommended_message_box_mac.h",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Copyright (c) 2021 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 "brave/browser/ui/views/renderer_context_menu/brave_render_view_context_menu_views.h"

BraveRenderViewContextMenuViews::BraveRenderViewContextMenuViews(
content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params)
: RenderViewContextMenuViews(render_frame_host, params) {}

BraveRenderViewContextMenuViews::~BraveRenderViewContextMenuViews() = default;

// static
RenderViewContextMenuViews* BraveRenderViewContextMenuViews::Create(
content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params) {
return new BraveRenderViewContextMenuViews(render_frame_host, params);
}

void BraveRenderViewContextMenuViews::Show() {
// Removes duplicated separator if any. The duplicated separator may appear
// in |BraveRenderViewContextMenu::InitMenu| after remove the translate menu
// item.
RemoveAdjacentSeparators();
RenderViewContextMenuViews::Show();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Copyright (c) 2021 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_BROWSER_UI_VIEWS_RENDERER_CONTEXT_MENU_BRAVE_RENDER_VIEW_CONTEXT_MENU_VIEWS_H_
#define BRAVE_BROWSER_UI_VIEWS_RENDERER_CONTEXT_MENU_BRAVE_RENDER_VIEW_CONTEXT_MENU_VIEWS_H_

#include "chrome/browser/ui/views/renderer_context_menu/render_view_context_menu_views.h"

class BraveRenderViewContextMenuViews : public RenderViewContextMenuViews {
public:
~BraveRenderViewContextMenuViews() override;
BraveRenderViewContextMenuViews(const BraveRenderViewContextMenuViews&) =
delete;
BraveRenderViewContextMenuViews& operator=(
const BraveRenderViewContextMenuViews&) = delete;

// Factory function to create an instance.
static RenderViewContextMenuViews* Create(
content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params);

void Show() override;

protected:
BraveRenderViewContextMenuViews(content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params);
};

#endif // BRAVE_BROWSER_UI_VIEWS_RENDERER_CONTEXT_MENU_BRAVE_RENDER_VIEW_CONTEXT_MENU_VIEWS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ void BraveRenderViewContextMenu::InitMenu() {
#endif

// Only show the translate item when go-translate is enabled.
// This removes menu item, but keeps the duplicated separator. The duplicated
// separator is removed in |BraveRenderViewContextMenuViews::Show|
#if !BUILDFLAG(ENABLE_BRAVE_TRANSLATE_GO)
index = menu_model_.GetIndexOfCommandId(IDC_CONTENT_CONTEXT_TRANSLATE);
if (index != -1)
Expand Down
3 changes: 3 additions & 0 deletions chromium_src/chrome/browser/ui/views/tab_contents/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+../../../../../../../chrome/browser/ui/views/tab_contents",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Copyright (c) 2021 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 "brave/browser/ui/views/renderer_context_menu/brave_render_view_context_menu_views.h"

#define RenderViewContextMenuViews BraveRenderViewContextMenuViews
#include "../../../../../../../chrome/browser/ui/views/tab_contents/chrome_web_contents_view_delegate_views.cc"
#undef RenderViewContextMenuViews

0 comments on commit 702d950

Please sign in to comment.