зеркало из https://github.com/electron/electron.git
feat: implement 'app-command' events for browser history navigation keys on Linux (#15441)
* Added mouse forward/back button support on Linux * Added browser history navigation action bindings for Windows, Mac, and Linux keyboard * Removed new `history-action` event and modified `app-command` to execute on such events * Removed attempt at macOS support and added constants * Clarified app-command documentation * Reverted 'app-command' description change * Format code
This commit is contained in:
Родитель
3f15f51615
Коммит
d243a45173
|
@ -267,7 +267,7 @@ void TopLevelWindow::OnWindowAlwaysOnTopChanged() {
|
|||
Emit("always-on-top-changed", IsAlwaysOnTop());
|
||||
}
|
||||
|
||||
void TopLevelWindow::OnExecuteWindowsCommand(const std::string& command_name) {
|
||||
void TopLevelWindow::OnExecuteAppCommand(const std::string& command_name) {
|
||||
Emit("app-command", command_name);
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
|
|||
void OnWindowEnterHtmlFullScreen() override;
|
||||
void OnWindowLeaveHtmlFullScreen() override;
|
||||
void OnWindowAlwaysOnTopChanged() override;
|
||||
void OnExecuteWindowsCommand(const std::string& command_name) override;
|
||||
void OnExecuteAppCommand(const std::string& command_name) override;
|
||||
void OnTouchBarItemResult(const std::string& item_id,
|
||||
const base::DictionaryValue& details) override;
|
||||
void OnNewWindowForTab() override;
|
||||
|
|
|
@ -540,10 +540,9 @@ void NativeWindow::NotifyWindowAlwaysOnTopChanged() {
|
|||
observer.OnWindowAlwaysOnTopChanged();
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowExecuteWindowsCommand(
|
||||
const std::string& command) {
|
||||
void NativeWindow::NotifyWindowExecuteAppCommand(const std::string& command) {
|
||||
for (NativeWindowObserver& observer : observers_)
|
||||
observer.OnExecuteWindowsCommand(command);
|
||||
observer.OnExecuteAppCommand(command);
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyTouchBarItemInteraction(
|
||||
|
|
|
@ -257,7 +257,7 @@ class NativeWindow : public base::SupportsUserData,
|
|||
void NotifyWindowEnterHtmlFullScreen();
|
||||
void NotifyWindowLeaveHtmlFullScreen();
|
||||
void NotifyWindowAlwaysOnTopChanged();
|
||||
void NotifyWindowExecuteWindowsCommand(const std::string& command);
|
||||
void NotifyWindowExecuteAppCommand(const std::string& command);
|
||||
void NotifyTouchBarItemInteraction(const std::string& item_id,
|
||||
const base::DictionaryValue& details);
|
||||
void NotifyNewWindowForTab();
|
||||
|
|
|
@ -95,7 +95,8 @@ class NativeWindowObserver : public base::CheckedObserver {
|
|||
#endif
|
||||
|
||||
// Called on Windows when App Commands arrive (WM_APPCOMMAND)
|
||||
virtual void OnExecuteWindowsCommand(const std::string& command_name) {}
|
||||
// Some commands are implemented on on other platforms as well
|
||||
virtual void OnExecuteAppCommand(const std::string& command_name) {}
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "atom/browser/web_contents_preferences.h"
|
||||
#include "atom/browser/web_view_manager.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "atom/common/draggable_region.h"
|
||||
#include "atom/common/native_mate_converters/image_converter.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
|
@ -287,6 +288,13 @@ NativeWindowViews::NativeWindowViews(const mate::Dictionary& options,
|
|||
last_window_state_ = ui::SHOW_STATE_NORMAL;
|
||||
last_normal_bounds_ = GetBounds();
|
||||
#endif
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
// Listen to move events.
|
||||
aura::Window* window = GetNativeWindow();
|
||||
if (window)
|
||||
window->AddPreTargetHandler(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
NativeWindowViews::~NativeWindowViews() {
|
||||
|
@ -296,6 +304,12 @@ NativeWindowViews::~NativeWindowViews() {
|
|||
// Disable mouse forwarding to relinquish resources, should any be held.
|
||||
SetForwardMouseMessages(false);
|
||||
#endif
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
aura::Window* window = GetNativeWindow();
|
||||
if (window)
|
||||
window->RemovePreTargetHandler(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetContentView(views::View* view) {
|
||||
|
@ -1274,11 +1288,30 @@ void NativeWindowViews::OnWidgetMove() {
|
|||
void NativeWindowViews::HandleKeyboardEvent(
|
||||
content::WebContents*,
|
||||
const content::NativeWebKeyboardEvent& event) {
|
||||
#if defined(OS_LINUX)
|
||||
if (event.windows_key_code == ui::VKEY_BROWSER_BACK)
|
||||
NotifyWindowExecuteAppCommand(kBrowserBackward);
|
||||
else if (event.windows_key_code == ui::VKEY_BROWSER_FORWARD)
|
||||
NotifyWindowExecuteAppCommand(kBrowserForward);
|
||||
#endif
|
||||
|
||||
keyboard_event_handler_->HandleKeyboardEvent(event,
|
||||
root_view_->GetFocusManager());
|
||||
root_view_->HandleKeyEvent(event);
|
||||
}
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
void NativeWindowViews::OnMouseEvent(ui::MouseEvent* event) {
|
||||
if (event->type() != ui::ET_MOUSE_PRESSED)
|
||||
return;
|
||||
|
||||
if (event->changed_button_flags() == ui::EF_BACK_MOUSE_BUTTON)
|
||||
NotifyWindowExecuteAppCommand(kBrowserBackward);
|
||||
else if (event->changed_button_flags() == ui::EF_FORWARD_MOUSE_BUTTON)
|
||||
NotifyWindowExecuteAppCommand(kBrowserForward);
|
||||
}
|
||||
#endif
|
||||
|
||||
ui::WindowShowState NativeWindowViews::GetRestoredState() {
|
||||
if (IsMaximized())
|
||||
return ui::SHOW_STATE_MAXIMIZED;
|
||||
|
|
|
@ -40,7 +40,8 @@ class NativeWindowViews : public NativeWindow,
|
|||
#if defined(OS_WIN)
|
||||
public MessageHandlerDelegate,
|
||||
#endif
|
||||
public views::WidgetObserver {
|
||||
public views::WidgetObserver,
|
||||
public ui::EventHandler {
|
||||
public:
|
||||
NativeWindowViews(const mate::Dictionary& options, NativeWindow* parent);
|
||||
~NativeWindowViews() override;
|
||||
|
@ -204,6 +205,11 @@ class NativeWindowViews : public NativeWindow,
|
|||
content::WebContents*,
|
||||
const content::NativeWebKeyboardEvent& event) override;
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
// ui::EventHandler:
|
||||
void OnMouseEvent(ui::MouseEvent* event) override;
|
||||
#endif
|
||||
|
||||
// Returns the restore state for the window.
|
||||
ui::WindowShowState GetRestoredState();
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/native_window_views.h"
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "content/public/browser/browser_accessibility_state.h"
|
||||
#include "ui/base/win/accessibility_misc_utils.h"
|
||||
|
||||
|
@ -18,9 +19,9 @@ namespace {
|
|||
const char* AppCommandToString(int command_id) {
|
||||
switch (command_id) {
|
||||
case APPCOMMAND_BROWSER_BACKWARD:
|
||||
return "browser-backward";
|
||||
return kBrowserBackward;
|
||||
case APPCOMMAND_BROWSER_FORWARD:
|
||||
return "browser-forward";
|
||||
return kBrowserForward;
|
||||
case APPCOMMAND_BROWSER_REFRESH:
|
||||
return "browser-refresh";
|
||||
case APPCOMMAND_BROWSER_STOP:
|
||||
|
@ -141,7 +142,7 @@ HHOOK NativeWindowViews::mouse_hook_ = NULL;
|
|||
|
||||
bool NativeWindowViews::ExecuteWindowsCommand(int command_id) {
|
||||
std::string command = AppCommandToString(command_id);
|
||||
NotifyWindowExecuteWindowsCommand(command);
|
||||
NotifyWindowExecuteAppCommand(command);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
namespace atom {
|
||||
|
||||
const char kBrowserForward[] = "browser-forward";
|
||||
const char kBrowserBackward[] = "browser-backward";
|
||||
|
||||
const char kCORSHeader[] = "Access-Control-Allow-Origin: *";
|
||||
|
||||
const char kSHA1Certificate[] = "SHA-1 Certificate";
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
|
||||
namespace atom {
|
||||
|
||||
// The app-command in NativeWindow.
|
||||
extern const char kBrowserForward[];
|
||||
extern const char kBrowserBackward[];
|
||||
|
||||
// Header to ignore CORS.
|
||||
extern const char kCORSHeader[];
|
||||
|
||||
|
|
|
@ -554,7 +554,7 @@ Returns:
|
|||
|
||||
Emitted when the window is set or unset to show always on top of other windows.
|
||||
|
||||
#### Event: 'app-command' _Windows_
|
||||
#### Event: 'app-command' _Windows_ _Linux_
|
||||
|
||||
Returns:
|
||||
|
||||
|
@ -580,6 +580,11 @@ win.on('app-command', (e, cmd) => {
|
|||
})
|
||||
```
|
||||
|
||||
The following app commands are explictly supported on Linux:
|
||||
|
||||
* `browser-backward`
|
||||
* `browser-forward`
|
||||
|
||||
#### Event: 'scroll-touch-begin' _macOS_
|
||||
|
||||
Emitted when scroll wheel event phase has begun.
|
||||
|
|
Загрузка…
Ссылка в новой задаче