Commit 5f83d227 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

wayland: provide support for testing if window has capture

Wayland does implicit capture. This adds plumbing to track when the
WaylandWindow has implicit capture, and adds function to
PlatformWindow to test for capture.

Also notifies when activation changes.

BUG=none
TEST=covered by tests

Change-Id: I9d73ade6cb8e5e909fe3fe3940eb6f48b0dbd5c7
Reviewed-on: https://chromium-review.googlesource.com/998307
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548543}
parent af7a2420
...@@ -54,6 +54,9 @@ class AURA_EXPORT WindowTreeHostPlatform : public WindowTreeHost, ...@@ -54,6 +54,9 @@ class AURA_EXPORT WindowTreeHostPlatform : public WindowTreeHost,
void SetPlatformWindow(std::unique_ptr<ui::PlatformWindow> window); void SetPlatformWindow(std::unique_ptr<ui::PlatformWindow> window);
ui::PlatformWindow* platform_window() { return platform_window_.get(); } ui::PlatformWindow* platform_window() { return platform_window_.get(); }
const ui::PlatformWindow* platform_window() const {
return platform_window_.get();
}
// ui::PlatformWindowDelegate: // ui::PlatformWindowDelegate:
void OnBoundsChanged(const gfx::Rect& new_bounds) override; void OnBoundsChanged(const gfx::Rect& new_bounds) override;
......
...@@ -39,6 +39,10 @@ void PlatformWindowCast::SetBounds(const gfx::Rect& bounds) { ...@@ -39,6 +39,10 @@ void PlatformWindowCast::SetBounds(const gfx::Rect& bounds) {
void PlatformWindowCast::SetTitle(const base::string16& title) { void PlatformWindowCast::SetTitle(const base::string16& title) {
} }
bool PlatformWindowCast::HasCapture() const {
return false;
}
PlatformImeController* PlatformWindowCast::GetPlatformImeController() { PlatformImeController* PlatformWindowCast::GetPlatformImeController() {
return nullptr; return nullptr;
} }
......
...@@ -31,6 +31,7 @@ class PlatformWindowCast : public PlatformWindow, ...@@ -31,6 +31,7 @@ class PlatformWindowCast : public PlatformWindow,
void PrepareForShutdown() override {} void PrepareForShutdown() override {}
void SetCapture() override {} void SetCapture() override {}
void ReleaseCapture() override {} void ReleaseCapture() override {}
bool HasCapture() const override;
void ToggleFullscreen() override {} void ToggleFullscreen() override {}
void Maximize() override {} void Maximize() override {}
void Minimize() override {} void Minimize() override {}
......
...@@ -97,6 +97,10 @@ void DrmWindowHost::ReleaseCapture() { ...@@ -97,6 +97,10 @@ void DrmWindowHost::ReleaseCapture() {
window_manager_->UngrabEvents(widget_); window_manager_->UngrabEvents(widget_);
} }
bool DrmWindowHost::HasCapture() const {
return widget_ == window_manager_->event_grabber();
}
void DrmWindowHost::ToggleFullscreen() { void DrmWindowHost::ToggleFullscreen() {
} }
......
...@@ -67,6 +67,7 @@ class DrmWindowHost : public PlatformWindow, ...@@ -67,6 +67,7 @@ class DrmWindowHost : public PlatformWindow,
void SetTitle(const base::string16& title) override; void SetTitle(const base::string16& title) override;
void SetCapture() override; void SetCapture() override;
void ReleaseCapture() override; void ReleaseCapture() override;
bool HasCapture() const override;
void ToggleFullscreen() override; void ToggleFullscreen() override;
void Maximize() override; void Maximize() override;
void Minimize() override; void Minimize() override;
......
...@@ -56,6 +56,10 @@ void HeadlessWindow::SetCapture() {} ...@@ -56,6 +56,10 @@ void HeadlessWindow::SetCapture() {}
void HeadlessWindow::ReleaseCapture() {} void HeadlessWindow::ReleaseCapture() {}
bool HeadlessWindow::HasCapture() const {
return false;
}
void HeadlessWindow::ToggleFullscreen() {} void HeadlessWindow::ToggleFullscreen() {}
void HeadlessWindow::Maximize() {} void HeadlessWindow::Maximize() {}
......
...@@ -32,6 +32,7 @@ class HeadlessWindow : public PlatformWindow { ...@@ -32,6 +32,7 @@ class HeadlessWindow : public PlatformWindow {
void PrepareForShutdown() override; void PrepareForShutdown() override;
void SetCapture() override; void SetCapture() override;
void ReleaseCapture() override; void ReleaseCapture() override;
bool HasCapture() const override;
void ToggleFullscreen() override; void ToggleFullscreen() override;
void Maximize() override; void Maximize() override;
void Minimize() override; void Minimize() override;
......
...@@ -53,6 +53,9 @@ class WaylandConnection : public PlatformEventSource, ...@@ -53,6 +53,9 @@ class WaylandConnection : public PlatformEventSource,
int GetKeyboardModifiers(); int GetKeyboardModifiers();
// Returns the current pointer, which may be null.
WaylandPointer* pointer() { return pointer_.get(); }
private: private:
void Flush(); void Flush();
void DispatchUiEvent(Event* event); void DispatchUiEvent(Event* event);
......
...@@ -23,6 +23,12 @@ bool VerifyFlagsAfterMasking(int flags, int original_flags, int modifiers) { ...@@ -23,6 +23,12 @@ bool VerifyFlagsAfterMasking(int flags, int original_flags, int modifiers) {
return flags == original_flags; return flags == original_flags;
} }
bool HasAnyButtonFlag(int flags) {
return (flags & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON |
EF_RIGHT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON |
EF_FORWARD_MOUSE_BUTTON)) != 0;
}
} // namespace } // namespace
WaylandPointer::WaylandPointer(wl_pointer* pointer, WaylandPointer::WaylandPointer(wl_pointer* pointer,
...@@ -38,7 +44,12 @@ WaylandPointer::WaylandPointer(wl_pointer* pointer, ...@@ -38,7 +44,12 @@ WaylandPointer::WaylandPointer(wl_pointer* pointer,
cursor_.reset(new WaylandCursor); cursor_.reset(new WaylandCursor);
} }
WaylandPointer::~WaylandPointer() {} WaylandPointer::~WaylandPointer() {
if (window_with_pointer_focus_) {
window_with_pointer_focus_->set_pointer_focus(false);
window_with_pointer_focus_->set_has_implicit_grab(false);
}
}
// static // static
void WaylandPointer::Enter(void* data, void WaylandPointer::Enter(void* data,
...@@ -50,8 +61,11 @@ void WaylandPointer::Enter(void* data, ...@@ -50,8 +61,11 @@ void WaylandPointer::Enter(void* data,
WaylandPointer* pointer = static_cast<WaylandPointer*>(data); WaylandPointer* pointer = static_cast<WaylandPointer*>(data);
pointer->location_.SetPoint(wl_fixed_to_double(surface_x), pointer->location_.SetPoint(wl_fixed_to_double(surface_x),
wl_fixed_to_double(surface_y)); wl_fixed_to_double(surface_y));
if (surface) if (surface) {
WaylandWindow::FromSurface(surface)->set_pointer_focus(true); WaylandWindow* window = WaylandWindow::FromSurface(surface);
window->set_pointer_focus(true);
pointer->window_with_pointer_focus_ = window;
}
} }
// static // static
...@@ -63,8 +77,11 @@ void WaylandPointer::Leave(void* data, ...@@ -63,8 +77,11 @@ void WaylandPointer::Leave(void* data,
MouseEvent event(ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), MouseEvent event(ET_MOUSE_EXITED, gfx::Point(), gfx::Point(),
EventTimeForNow(), pointer->flags_, 0); EventTimeForNow(), pointer->flags_, 0);
pointer->callback_.Run(&event); pointer->callback_.Run(&event);
if (surface) if (surface) {
WaylandWindow::FromSurface(surface)->set_pointer_focus(false); WaylandWindow* window = WaylandWindow::FromSurface(surface);
window->set_pointer_focus(false);
pointer->window_with_pointer_focus_ = nullptr;
}
} }
// static // static
...@@ -123,6 +140,11 @@ void WaylandPointer::Button(void* data, ...@@ -123,6 +140,11 @@ void WaylandPointer::Button(void* data,
pointer->flags_ &= ~changed_button; pointer->flags_ &= ~changed_button;
} }
if (pointer->window_with_pointer_focus_) {
pointer->window_with_pointer_focus_->set_has_implicit_grab(
HasAnyButtonFlag(pointer->flags_));
}
// MouseEvent's flags should contain the button that was released too. // MouseEvent's flags should contain the button that was released too.
const int flags = pointer->GetFlagsWithKeyboardModifiers() | changed_button; const int flags = pointer->GetFlagsWithKeyboardModifiers() | changed_button;
MouseEvent event(type, gfx::Point(), gfx::Point(), MouseEvent event(type, gfx::Point(), gfx::Point(),
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef UI_OZONE_PLATFORM_WAYLAND_WAYLAND_POINTER_H_ #ifndef UI_OZONE_PLATFORM_WAYLAND_WAYLAND_POINTER_H_
#define UI_OZONE_PLATFORM_WAYLAND_WAYLAND_POINTER_H_ #define UI_OZONE_PLATFORM_WAYLAND_WAYLAND_POINTER_H_
#include "base/macros.h"
#include "ui/events/ozone/evdev/event_dispatch_callback.h" #include "ui/events/ozone/evdev/event_dispatch_callback.h"
#include "ui/gfx/geometry/point_f.h" #include "ui/gfx/geometry/point_f.h"
#include "ui/ozone/platform/wayland/wayland_cursor.h" #include "ui/ozone/platform/wayland/wayland_cursor.h"
...@@ -12,6 +13,8 @@ ...@@ -12,6 +13,8 @@
namespace ui { namespace ui {
class WaylandWindow;
class WaylandPointer { class WaylandPointer {
public: public:
WaylandPointer(wl_pointer* pointer, const EventDispatchCallback& callback); WaylandPointer(wl_pointer* pointer, const EventDispatchCallback& callback);
...@@ -26,6 +29,10 @@ class WaylandPointer { ...@@ -26,6 +29,10 @@ class WaylandPointer {
WaylandCursor* cursor() { return cursor_.get(); } WaylandCursor* cursor() { return cursor_.get(); }
void reset_window_with_pointer_focus() {
window_with_pointer_focus_ = nullptr;
}
private: private:
// wl_pointer_listener // wl_pointer_listener
static void Enter(void* data, static void Enter(void* data,
...@@ -60,11 +67,18 @@ class WaylandPointer { ...@@ -60,11 +67,18 @@ class WaylandPointer {
wl::Object<wl_pointer> obj_; wl::Object<wl_pointer> obj_;
EventDispatchCallback callback_; EventDispatchCallback callback_;
gfx::PointF location_; gfx::PointF location_;
// Flags is a bitmask of EventFlags corresponding to the pointer/keyboard
// state.
int flags_ = 0; int flags_ = 0;
// Keeps track of current modifiers. These are needed in order to properly // Keeps track of current modifiers. These are needed in order to properly
// update |flags_| with newest modifiers. // update |flags_| with newest modifiers.
int keyboard_modifiers_ = 0; int keyboard_modifiers_ = 0;
// The window the mouse is over.
WaylandWindow* window_with_pointer_focus_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(WaylandPointer);
}; };
} // namespace ui } // namespace ui
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/ozone/events_ozone.h" #include "ui/events/ozone/events_ozone.h"
#include "ui/ozone/platform/wayland/wayland_connection.h" #include "ui/ozone/platform/wayland/wayland_connection.h"
#include "ui/ozone/platform/wayland/wayland_pointer.h"
#include "ui/ozone/platform/wayland/xdg_surface_wrapper_v5.h" #include "ui/ozone/platform/wayland/xdg_surface_wrapper_v5.h"
#include "ui/ozone/platform/wayland/xdg_surface_wrapper_v6.h" #include "ui/ozone/platform/wayland/xdg_surface_wrapper_v6.h"
...@@ -55,6 +56,8 @@ WaylandWindow::~WaylandWindow() { ...@@ -55,6 +56,8 @@ WaylandWindow::~WaylandWindow() {
PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
connection_->RemoveWindow(surface_.id()); connection_->RemoveWindow(surface_.id());
} }
if (has_pointer_focus_)
connection_->pointer()->reset_window_with_pointer_focus();
} }
// static // static
...@@ -134,13 +137,21 @@ void WaylandWindow::SetTitle(const base::string16& title) { ...@@ -134,13 +137,21 @@ void WaylandWindow::SetTitle(const base::string16& title) {
} }
void WaylandWindow::SetCapture() { void WaylandWindow::SetCapture() {
// Wayland does implicit grabs, and doesn't allow for explicit grabs. The
// exception to that seems to be popups, which can do a grab during show. Need
// to evaluate under what circumstances we need this.
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
void WaylandWindow::ReleaseCapture() { void WaylandWindow::ReleaseCapture() {
// See comment in SetCapture() for details on wayland and grabs.
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
bool WaylandWindow::HasCapture() const {
return has_implicit_grab_;
}
void WaylandWindow::ToggleFullscreen() { void WaylandWindow::ToggleFullscreen() {
DCHECK(xdg_surface_); DCHECK(xdg_surface_);
...@@ -267,14 +278,21 @@ void WaylandWindow::HandleSurfaceConfigure(int32_t width, ...@@ -267,14 +278,21 @@ void WaylandWindow::HandleSurfaceConfigure(int32_t width,
else else
state_ = PlatformWindowState::PLATFORM_WINDOW_STATE_NORMAL; state_ = PlatformWindowState::PLATFORM_WINDOW_STATE_NORMAL;
if (old_state != state_) // Update state before notifying delegate.
delegate_->OnWindowStateChanged(state_); const bool did_active_change = is_active_ != is_activated;
is_active_ = is_activated;
// Rather than call SetBounds here for every configure event, just save the // Rather than call SetBounds here for every configure event, just save the
// most recent bounds, and have WaylandConnection call ApplyPendingBounds // most recent bounds, and have WaylandConnection call ApplyPendingBounds
// when it has finished processing events. We may get many configure events // when it has finished processing events. We may get many configure events
// in a row during an interactive resize, and only the last one matters. // in a row during an interactive resize, and only the last one matters.
SetPendingBounds(width, height); SetPendingBounds(width, height);
if (old_state != state_)
delegate_->OnWindowStateChanged(state_);
if (did_active_change)
delegate_->OnActivationChanged(is_active_);
} }
void WaylandWindow::OnCloseRequest() { void WaylandWindow::OnCloseRequest() {
......
...@@ -43,6 +43,7 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher { ...@@ -43,6 +43,7 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher {
// Set whether this window has pointer focus and should dispatch mouse events. // Set whether this window has pointer focus and should dispatch mouse events.
void set_pointer_focus(bool focus) { has_pointer_focus_ = focus; } void set_pointer_focus(bool focus) { has_pointer_focus_ = focus; }
bool has_pointer_focus() const { return has_pointer_focus_; }
// Set whether this window has keyboard focus and should dispatch key events. // Set whether this window has keyboard focus and should dispatch key events.
void set_keyboard_focus(bool focus) { has_keyboard_focus_ = focus; } void set_keyboard_focus(bool focus) { has_keyboard_focus_ = focus; }
...@@ -50,6 +51,13 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher { ...@@ -50,6 +51,13 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher {
// Set whether this window has touch focus and should dispatch touch events. // Set whether this window has touch focus and should dispatch touch events.
void set_touch_focus(bool focus) { has_touch_focus_ = focus; } void set_touch_focus(bool focus) { has_touch_focus_ = focus; }
// Set whether this window has an implicit grab (often referred to as capture
// in Chrome code). Implicit grabs happen while a pointer is down.
void set_has_implicit_grab(bool value) { has_implicit_grab_ = value; }
bool has_implicit_grab() const { return has_implicit_grab_; }
bool is_active() const { return is_active_; }
// PlatformWindow // PlatformWindow
void Show() override; void Show() override;
void Hide() override; void Hide() override;
...@@ -60,6 +68,7 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher { ...@@ -60,6 +68,7 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher {
void SetTitle(const base::string16& title) override; void SetTitle(const base::string16& title) override;
void SetCapture() override; void SetCapture() override;
void ReleaseCapture() override; void ReleaseCapture() override;
bool HasCapture() const override;
void ToggleFullscreen() override; void ToggleFullscreen() override;
void Maximize() override; void Maximize() override;
void Minimize() override; void Minimize() override;
...@@ -113,10 +122,13 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher { ...@@ -113,10 +122,13 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher {
bool has_pointer_focus_ = false; bool has_pointer_focus_ = false;
bool has_keyboard_focus_ = false; bool has_keyboard_focus_ = false;
bool has_touch_focus_ = false; bool has_touch_focus_ = false;
bool has_implicit_grab_ = false;
// Stores current states of the window. // Stores current states of the window.
ui::PlatformWindowState state_; ui::PlatformWindowState state_;
bool is_active_ = false;
DISALLOW_COPY_AND_ASSIGN(WaylandWindow); DISALLOW_COPY_AND_ASSIGN(WaylandWindow);
}; };
......
...@@ -323,13 +323,18 @@ TEST_P(WaylandWindowTest, CanDispatchMouseEventDefault) { ...@@ -323,13 +323,18 @@ TEST_P(WaylandWindowTest, CanDispatchMouseEventDefault) {
} }
TEST_P(WaylandWindowTest, CanDispatchMouseEventFocus) { TEST_P(WaylandWindowTest, CanDispatchMouseEventFocus) {
// set_pointer_focus(true) requires a WaylandPointer.
wl_seat_send_capabilities(server_.seat()->resource(),
WL_SEAT_CAPABILITY_POINTER);
Sync();
ASSERT_TRUE(connection_->pointer());
window_->set_pointer_focus(true); window_->set_pointer_focus(true);
EXPECT_TRUE(window_->CanDispatchEvent(&test_mouse_event_)); EXPECT_TRUE(window_->CanDispatchEvent(&test_mouse_event_));
} }
TEST_P(WaylandWindowTest, CanDispatchMouseEventUnfocus) { TEST_P(WaylandWindowTest, CanDispatchMouseEventUnfocus) {
window_->set_pointer_focus(true); EXPECT_FALSE(window_->has_pointer_focus());
EXPECT_TRUE(window_->CanDispatchEvent(&test_mouse_event_)); EXPECT_FALSE(window_->CanDispatchEvent(&test_mouse_event_));
} }
ACTION_P(CloneEvent, ptr) { ACTION_P(CloneEvent, ptr) {
...@@ -352,6 +357,35 @@ TEST_P(WaylandWindowTest, DispatchEvent) { ...@@ -352,6 +357,35 @@ TEST_P(WaylandWindowTest, DispatchEvent) {
test_mouse_event_.changed_button_flags()); test_mouse_event_.changed_button_flags());
} }
TEST_P(WaylandWindowTest, HasCaptureUpdatedOnPointerEvents) {
wl_seat_send_capabilities(server_.seat()->resource(),
WL_SEAT_CAPABILITY_POINTER);
Sync();
wl::MockPointer* pointer = server_.seat()->pointer_.get();
ASSERT_TRUE(pointer);
wl_pointer_send_enter(pointer->resource(), 1, surface_->resource(), 0, 0);
Sync();
EXPECT_FALSE(window_->HasCapture());
wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_LEFT,
WL_POINTER_BUTTON_STATE_PRESSED);
Sync();
EXPECT_TRUE(window_->HasCapture());
wl_pointer_send_motion(pointer->resource(), 1003, wl_fixed_from_int(400),
wl_fixed_from_int(500));
Sync();
EXPECT_TRUE(window_->HasCapture());
wl_pointer_send_button(pointer->resource(), 4, 1004, BTN_LEFT,
WL_POINTER_BUTTON_STATE_RELEASED);
Sync();
EXPECT_FALSE(window_->HasCapture());
}
TEST_P(WaylandWindowTest, ConfigureEvent) { TEST_P(WaylandWindowTest, ConfigureEvent) {
wl_array states; wl_array states;
wl_array_init(&states); wl_array_init(&states);
...@@ -385,6 +419,26 @@ TEST_P(WaylandWindowTest, ConfigureEventWithNulledSize) { ...@@ -385,6 +419,26 @@ TEST_P(WaylandWindowTest, ConfigureEventWithNulledSize) {
EXPECT_CALL(*xdg_surface_, AckConfigure(14)); EXPECT_CALL(*xdg_surface_, AckConfigure(14));
} }
TEST_P(WaylandWindowTest, OnActivationChanged) {
EXPECT_FALSE(window_->is_active());
{
wl_array states;
InitializeWlArrayWithActivatedState(&states);
EXPECT_CALL(delegate_, OnActivationChanged(Eq(true)));
SendConfigureEvent(0, 0, 1, &states);
Sync();
EXPECT_TRUE(window_->is_active());
}
wl_array states;
wl_array_init(&states);
EXPECT_CALL(delegate_, OnActivationChanged(Eq(false)));
SendConfigureEvent(0, 0, 2, &states);
Sync();
EXPECT_FALSE(window_->is_active());
}
INSTANTIATE_TEST_CASE_P(XdgVersionV5Test, INSTANTIATE_TEST_CASE_P(XdgVersionV5Test,
WaylandWindowTest, WaylandWindowTest,
::testing::Values(kXdgShellV5)); ::testing::Values(kXdgShellV5));
......
...@@ -196,6 +196,11 @@ void PlatformWindowAndroid::ReleaseCapture() { ...@@ -196,6 +196,11 @@ void PlatformWindowAndroid::ReleaseCapture() {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
bool PlatformWindowAndroid::HasCapture() const {
NOTIMPLEMENTED();
return false;
}
void PlatformWindowAndroid::ToggleFullscreen() { void PlatformWindowAndroid::ToggleFullscreen() {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
......
...@@ -71,6 +71,7 @@ class ANDROID_WINDOW_EXPORT PlatformWindowAndroid : public PlatformWindow { ...@@ -71,6 +71,7 @@ class ANDROID_WINDOW_EXPORT PlatformWindowAndroid : public PlatformWindow {
void SetTitle(const base::string16& title) override; void SetTitle(const base::string16& title) override;
void SetCapture() override; void SetCapture() override;
void ReleaseCapture() override; void ReleaseCapture() override;
bool HasCapture() const override;
void ToggleFullscreen() override; void ToggleFullscreen() override;
void Maximize() override; void Maximize() override;
void Minimize() override; void Minimize() override;
......
...@@ -45,6 +45,7 @@ class PlatformWindow { ...@@ -45,6 +45,7 @@ class PlatformWindow {
virtual void SetCapture() = 0; virtual void SetCapture() = 0;
virtual void ReleaseCapture() = 0; virtual void ReleaseCapture() = 0;
virtual bool HasCapture() const = 0;
virtual void ToggleFullscreen() = 0; virtual void ToggleFullscreen() = 0;
virtual void Maximize() = 0; virtual void Maximize() = 0;
......
...@@ -53,6 +53,10 @@ void StubWindow::SetCapture() { ...@@ -53,6 +53,10 @@ void StubWindow::SetCapture() {
void StubWindow::ReleaseCapture() { void StubWindow::ReleaseCapture() {
} }
bool StubWindow::HasCapture() const {
return false;
}
void StubWindow::ToggleFullscreen() { void StubWindow::ToggleFullscreen() {
} }
......
...@@ -37,6 +37,7 @@ class STUB_WINDOW_EXPORT StubWindow : public PlatformWindow { ...@@ -37,6 +37,7 @@ class STUB_WINDOW_EXPORT StubWindow : public PlatformWindow {
void SetCapture() override; void SetCapture() override;
void ReleaseCapture() override; void ReleaseCapture() override;
void ToggleFullscreen() override; void ToggleFullscreen() override;
bool HasCapture() const override;
void Maximize() override; void Maximize() override;
void Minimize() override; void Minimize() override;
void Restore() override; void Restore() override;
......
...@@ -101,15 +101,19 @@ void WinWindow::SetTitle(const base::string16& title) { ...@@ -101,15 +101,19 @@ void WinWindow::SetTitle(const base::string16& title) {
} }
void WinWindow::SetCapture() { void WinWindow::SetCapture() {
if (::GetCapture() != hwnd()) if (!HasCapture())
::SetCapture(hwnd()); ::SetCapture(hwnd());
} }
void WinWindow::ReleaseCapture() { void WinWindow::ReleaseCapture() {
if (::GetCapture() == hwnd()) if (HasCapture())
::ReleaseCapture(); ::ReleaseCapture();
} }
bool WinWindow::HasCapture() const {
return ::GetCapture() == hwnd();
}
void WinWindow::ToggleFullscreen() {} void WinWindow::ToggleFullscreen() {}
void WinWindow::Maximize() {} void WinWindow::Maximize() {}
......
...@@ -36,6 +36,7 @@ class WIN_WINDOW_EXPORT WinWindow : public PlatformWindow, ...@@ -36,6 +36,7 @@ class WIN_WINDOW_EXPORT WinWindow : public PlatformWindow,
void SetTitle(const base::string16& title) override; void SetTitle(const base::string16& title) override;
void SetCapture() override; void SetCapture() override;
void ReleaseCapture() override; void ReleaseCapture() override;
bool HasCapture() const override;
void ToggleFullscreen() override; void ToggleFullscreen() override;
void Maximize() override; void Maximize() override;
void Minimize() override; void Minimize() override;
......
...@@ -224,6 +224,10 @@ void X11WindowBase::SetCapture() {} ...@@ -224,6 +224,10 @@ void X11WindowBase::SetCapture() {}
void X11WindowBase::ReleaseCapture() {} void X11WindowBase::ReleaseCapture() {}
bool X11WindowBase::HasCapture() const {
return false;
}
void X11WindowBase::ToggleFullscreen() { void X11WindowBase::ToggleFullscreen() {
ui::SetWMSpecState(xwindow_, !IsFullscreen(), ui::SetWMSpecState(xwindow_, !IsFullscreen(),
gfx::GetAtom("_NET_WM_STATE_FULLSCREEN"), x11::None); gfx::GetAtom("_NET_WM_STATE_FULLSCREEN"), x11::None);
......
...@@ -39,6 +39,7 @@ class X11_WINDOW_EXPORT X11WindowBase : public PlatformWindow { ...@@ -39,6 +39,7 @@ class X11_WINDOW_EXPORT X11WindowBase : public PlatformWindow {
void SetTitle(const base::string16& title) override; void SetTitle(const base::string16& title) override;
void SetCapture() override; void SetCapture() override;
void ReleaseCapture() override; void ReleaseCapture() override;
bool HasCapture() const override;
void ToggleFullscreen() override; void ToggleFullscreen() override;
void Maximize() override; void Maximize() override;
void Minimize() override; void Minimize() override;
......
...@@ -271,9 +271,7 @@ bool DesktopWindowTreeHostPlatform::IsMinimized() const { ...@@ -271,9 +271,7 @@ bool DesktopWindowTreeHostPlatform::IsMinimized() const {
} }
bool DesktopWindowTreeHostPlatform::HasCapture() const { bool DesktopWindowTreeHostPlatform::HasCapture() const {
// TODO: needs PlatformWindow support. return platform_window()->HasCapture();
NOTIMPLEMENTED_LOG_ONCE();
return false;
} }
void DesktopWindowTreeHostPlatform::SetAlwaysOnTop(bool always_on_top) { void DesktopWindowTreeHostPlatform::SetAlwaysOnTop(bool always_on_top) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment