Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed May 14, 2020
1 parent 0008cef commit 1ff0e68
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 68 deletions.
1 change: 1 addition & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ source_set("ui") {
"brave_browser_command_controller.h",
"brave_browser_content_setting_bubble_model_delegate.cc",
"brave_browser_content_setting_bubble_model_delegate.h",
"brave_browser_window.h",
"brave_layout_constants.cc",
"brave_layout_constants.h",
"brave_pages.cc",
Expand Down
8 changes: 4 additions & 4 deletions browser/ui/brave_browser_window.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// /* Copyright (c) 2020 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/. */
/* Copyright (c) 2020 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_BRAVE_BROWSER_WINDOW_H_
#define BRAVE_BROWSER_UI_BRAVE_BROWSER_WINDOW_H_
Expand Down
9 changes: 1 addition & 8 deletions browser/ui/tabs/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import("//build/config/ui.gni")

source_set("tabs") {
sources = []

Expand All @@ -17,15 +15,10 @@ source_set("tabs") {
if (!is_android) {
deps += [
"//brave/common/",
"//chrome/app:generated_resources",
"//components/prefs",
"//components/sessions",
"//content/public/browser",
]

if(use_aura) {
deps += [
"//ui/aura"
]
}
}
}
83 changes: 48 additions & 35 deletions browser/ui/views/frame/brave_browser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "brave/browser/ui/views/frame/brave_browser_view.h"

#include <utility>

#include "brave/browser/sparkle_buildflags.h"
#include "brave/browser/translate/buildflags/buildflags.h"
#include "brave/browser/ui/views/toolbar/bookmark_button.h"
Expand All @@ -24,6 +26,52 @@
#include "extensions/browser/extension_registry.h"
#endif

namespace {

class CtrlReleaseHandler : public ui::EventHandler {
public:
explicit CtrlReleaseHandler(BraveTabStripModel* model,
BraveBrowserView* browser_view)
: model_(model), browser_view_(browser_view) {}
~CtrlReleaseHandler() override = default;

private:
// ui::EventHandler overrides:
void OnKeyEvent(ui::KeyEvent* event) override {
if (event->key_code() == ui::VKEY_CONTROL &&
event->type() == ui::ET_KEY_RELEASED) {
// Ctrl key was released, stop the MRU cycling

// Remove event handler
#if defined(OS_MACOSX)
if (browser_view_->GetWidget()->GetRootView())
browser_view_->GetWidget()->GetRootView()->RemovePreTargetHandler(this);
#else
if (browser_view_->GetWidget()->GetNativeWindow())
browser_view_->GetWidget()->GetNativeWindow()->RemovePreTargetHandler(
this);
#endif

model_->StopMRUCycling();
} else if (!((event->key_code() == ui::VKEY_TAB &&
event->type() == ui::ET_KEY_PRESSED) ||
(event->key_code() == ui::VKEY_PRIOR &&
event->type() == ui::ET_KEY_PRESSED) ||
(event->key_code() == ui::VKEY_NEXT &&
event->type() == ui::ET_KEY_PRESSED))) {
// Block all keys while cycling except tab,pg previous, pg next keys
event->StopPropagation();
}
}

BraveTabStripModel* model_;
BraveBrowserView* browser_view_;

DISALLOW_COPY_AND_ASSIGN(CtrlReleaseHandler);
};

} // namespace

BraveBrowserView::BraveBrowserView(std::unique_ptr<Browser> browser)
: BrowserView(std::move(browser)) {}

Expand Down Expand Up @@ -104,38 +152,3 @@ void BraveBrowserView::StartMRUCycling() {
ctrl_released_event_handler_.get());
#endif
}

BraveBrowserView::CtrlReleaseHandler::CtrlReleaseHandler(
BraveTabStripModel* model,
BraveBrowserView* browser_view)
: model_(model), browser_view_(browser_view) {}

BraveBrowserView::CtrlReleaseHandler::~CtrlReleaseHandler() = default;

void BraveBrowserView::CtrlReleaseHandler::OnKeyEvent(ui::KeyEvent* event) {
if (event->key_code() == ui::VKEY_CONTROL &&
event->type() == ui::ET_KEY_RELEASED) {
// Ctrl key was released, stop the MRU cycling

// Remove event handler
#if defined(OS_MACOSX)
if (browser_view_->GetWidget()->GetRootView())
browser_view_->GetWidget()->GetRootView()->RemovePreTargetHandler(this);
#else
if (browser_view_->GetWidget()->GetNativeWindow())
browser_view_->GetWidget()->GetNativeWindow()->RemovePreTargetHandler(
this);
#endif

model_->StopMRUCycling();

} else if (!((event->key_code() == ui::VKEY_TAB &&
event->type() == ui::ET_KEY_PRESSED) ||
(event->key_code() == ui::VKEY_PRIOR &&
event->type() == ui::ET_KEY_PRESSED) ||
(event->key_code() == ui::VKEY_NEXT &&
event->type() == ui::ET_KEY_PRESSED))) {
// Block all keys while cycling except tab,pg previous, pg next keys
event->StopPropagation();
}
}
18 changes: 3 additions & 15 deletions browser/ui/views/frame/brave_browser_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
#ifndef BRAVE_BROWSER_UI_VIEWS_FRAME_BRAVE_BROWSER_VIEW_H_
#define BRAVE_BROWSER_UI_VIEWS_FRAME_BRAVE_BROWSER_VIEW_H_

#include <memory>
#include <string>

#include "brave/browser/ui/tabs/brave_tab_strip_model.h"
#include "chrome/browser/ui/views/frame/browser_view.h"

class BraveBrowserView : public BrowserView {
public:
BraveBrowserView(std::unique_ptr<Browser> browser);
explicit BraveBrowserView(std::unique_ptr<Browser> browser);
~BraveBrowserView() override;

void SetStarredState(bool is_starred) override;
Expand All @@ -29,20 +30,7 @@ class BraveBrowserView : public BrowserView {
void StartMRUCycling() override;

private:
class CtrlReleaseHandler : public ui::EventHandler {
public:
explicit CtrlReleaseHandler(BraveTabStripModel* model,
BraveBrowserView* browser_view);
~CtrlReleaseHandler() override;

private:
void OnKeyEvent(ui::KeyEvent* event) override;
BraveTabStripModel* model_;
BraveBrowserView* browser_view_;
DISALLOW_COPY_AND_ASSIGN(CtrlReleaseHandler);
};

std::unique_ptr<CtrlReleaseHandler> ctrl_released_event_handler_;
std::unique_ptr<ui::EventHandler> ctrl_released_event_handler_;

DISALLOW_COPY_AND_ASSIGN(BraveBrowserView);
};
Expand Down
10 changes: 5 additions & 5 deletions browser/ui/views/frame/brave_browser_view_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/test/base/in_process_browser_test.h"

#if defined(USE_AURA)
#include "ui/aura/window.h"
#endif

using BraveBrowserViewTest = InProcessBrowserTest;

IN_PROC_BROWSER_TEST_F(BraveBrowserViewTest, MRUCyclingBasic) {
// Off by default.
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(kMRUCyclingEnabled));

TabStripModel* tab_strip_model = browser()->tab_strip_model();

// Open 3 tabs
Expand All @@ -28,7 +28,7 @@ IN_PROC_BROWSER_TEST_F(BraveBrowserViewTest, MRUCyclingBasic) {
chrome::ExecuteCommand(browser(), IDC_SELECT_NEXT_TAB);
EXPECT_EQ(tab_strip_model->active_index(), 0);

// // Activate MRU cycling
// Activate MRU cycling
browser()->profile()->GetPrefs()->SetBoolean(kMRUCyclingEnabled, true);

// MRU cycling, 0 -> 2
Expand Down
3 changes: 2 additions & 1 deletion chromium_src/chrome/browser/ui/tabs/tab_strip_model.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
/* Copyright (c) 2020 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/. */
Expand All @@ -11,5 +11,6 @@

#include "../../../../../../chrome/browser/ui/tabs/tab_strip_model.h" // NOLINT
#undef SelectRelativeTab
#undef TAB_STRIP_MODEL_H_

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_TABS_TAB_STRIP_MODEL_H_

0 comments on commit 1ff0e68

Please sign in to comment.