diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/ui/ozone/platform/x11 | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/ui/ozone/platform/x11')
20 files changed, 184 insertions, 813 deletions
diff --git a/chromium/ui/ozone/platform/x11/BUILD.gn b/chromium/ui/ozone/platform/x11/BUILD.gn index fcdb99cdf60..35b64eb2caa 100644 --- a/chromium/ui/ozone/platform/x11/BUILD.gn +++ b/chromium/ui/ozone/platform/x11/BUILD.gn @@ -24,18 +24,12 @@ source_set("x11") { "x11_canvas_surface.h", "x11_clipboard_ozone.cc", "x11_clipboard_ozone.h", - "x11_cursor_factory_ozone.cc", - "x11_cursor_factory_ozone.h", - "x11_cursor_ozone.cc", - "x11_cursor_ozone.h", "x11_screen_ozone.cc", "x11_screen_ozone.h", "x11_surface_factory.cc", "x11_surface_factory.h", ] - public_deps = [ "//ui/base/cursor/mojom:cursor_type" ] - deps = [ "//base", "//build:chromecast_buildflags", @@ -45,6 +39,7 @@ source_set("x11") { "//ui/base:buildflags", "//ui/base:data_exchange", "//ui/base/clipboard:clipboard_types", + "//ui/base/cursor:cursor_base", "//ui/base/ime", "//ui/base/x", "//ui/base/x:gl", @@ -68,17 +63,11 @@ source_set("x11") { ] if (is_chromeos) { - sources += [ - "x11_window_ozone_chromeos.cc", - "x11_window_ozone_chromeos.h", - ] deps += [ "//ui/base/ime/chromeos" ] } else { sources += [ "x11_os_exchange_data_provider_ozone.cc", "x11_os_exchange_data_provider_ozone.h", - "x11_window_ozone.cc", - "x11_window_ozone.h", ] deps += [ "//ui/base/ime/linux" ] } @@ -101,7 +90,6 @@ source_set("x11") { source_set("x11_unittests") { testonly = true sources = [ - "x11_cursor_factory_ozone_unittest.cc", "x11_screen_ozone_unittest.cc", "x11_window_ozone_unittest.cc", ] diff --git a/chromium/ui/ozone/platform/x11/ozone_platform_x11.cc b/chromium/ui/ozone/platform/x11/ozone_platform_x11.cc index 2d26ced5587..394ef374c81 100644 --- a/chromium/ui/ozone/platform/x11/ozone_platform_x11.cc +++ b/chromium/ui/ozone/platform/x11/ozone_platform_x11.cc @@ -11,9 +11,11 @@ #include "base/strings/utf_string_conversions.h" #include "build/build_config.h" #include "ui/base/buildflags.h" +#include "ui/base/cursor/cursor_factory.h" #include "ui/base/dragdrop/os_exchange_data_provider_factory.h" #include "ui/base/dragdrop/os_exchange_data_provider_factory_ozone.h" -#include "ui/base/ime/linux/linux_input_method_context_factory.h" +#include "ui/base/x/x11_cursor_factory.h" +#include "ui/base/x/x11_error_handler.h" #include "ui/base/x/x11_util.h" #include "ui/display/fake/fake_display_delegate.h" #include "ui/events/devices/x11/touch_factory_x11.h" @@ -25,22 +27,22 @@ #include "ui/ozone/common/stub_overlay_manager.h" #include "ui/ozone/platform/x11/gl_egl_utility_x11.h" #include "ui/ozone/platform/x11/x11_clipboard_ozone.h" -#include "ui/ozone/platform/x11/x11_cursor_factory_ozone.h" #include "ui/ozone/platform/x11/x11_screen_ozone.h" #include "ui/ozone/platform/x11/x11_surface_factory.h" -#include "ui/ozone/platform/x11/x11_window_ozone.h" #include "ui/ozone/public/gpu_platform_support_host.h" #include "ui/ozone/public/input_controller.h" #include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/system_input_injector.h" #include "ui/platform_window/platform_window.h" #include "ui/platform_window/platform_window_init_properties.h" +#include "ui/platform_window/x11/x11_window.h" #if defined(OS_CHROMEOS) -#include "ui/base/dragdrop/os_exchange_data_provider_aura.h" +#include "ui/base/dragdrop/os_exchange_data_provider_non_backed.h" #include "ui/base/ime/chromeos/input_method_chromeos.h" #else -#include "ui/base/ime/linux/input_method_auralinux.h" +#include "ui/base/ime/linux/input_method_auralinux.h" // nogncheck +#include "ui/base/ime/linux/linux_input_method_context_factory.h" // nogncheck #include "ui/ozone/platform/x11/x11_os_exchange_data_provider_ozone.h" #endif @@ -88,9 +90,7 @@ class OzonePlatformX11 : public OzonePlatform, return overlay_manager_.get(); } - CursorFactoryOzone* GetCursorFactoryOzone() override { - return cursor_factory_ozone_.get(); - } + CursorFactory* GetCursorFactory() override { return cursor_factory_.get(); } std::unique_ptr<SystemInputInjector> CreateSystemInputInjector() override { return nullptr; @@ -107,8 +107,7 @@ class OzonePlatformX11 : public OzonePlatform, std::unique_ptr<PlatformWindow> CreatePlatformWindow( PlatformWindowDelegate* delegate, PlatformWindowInitProperties properties) override { - std::unique_ptr<X11WindowOzone> window = - std::make_unique<X11WindowOzone>(delegate); + auto window = std::make_unique<X11Window>(delegate); window->Initialize(std::move(properties)); window->SetTitle(base::ASCIIToUTF16("Ozone X11")); return std::move(window); @@ -151,7 +150,7 @@ class OzonePlatformX11 : public OzonePlatform, std::unique_ptr<OSExchangeDataProvider> CreateProvider() override { #if defined(OS_CHROMEOS) - return std::make_unique<OSExchangeDataProviderAura>(); + return std::make_unique<OSExchangeDataProviderNonBacked>(); #else return std::make_unique<X11OSExchangeDataProviderOzone>(); #endif @@ -167,7 +166,7 @@ class OzonePlatformX11 : public OzonePlatform, overlay_manager_ = std::make_unique<StubOverlayManager>(); input_controller_ = CreateStubInputController(); clipboard_ = std::make_unique<X11ClipboardOzone>(); - cursor_factory_ozone_ = std::make_unique<X11CursorFactoryOzone>(); + cursor_factory_ = std::make_unique<X11CursorFactory>(); gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); #if BUILDFLAG(USE_XKBCOMMON) @@ -202,6 +201,28 @@ class OzonePlatformX11 : public OzonePlatform, gl_egl_utility_ = std::make_unique<GLEGLUtilityX11>(); } + void PostMainMessageLoopStart( + base::OnceCallback<void()> shutdown_cb) override { + // Installs the X11 error handlers for the UI process after the + // main message loop has started. This will allow us to exit cleanly + // if X exits before we do. + SetErrorHandlers(std::move(shutdown_cb)); + } + + void PostMainMessageLoopRun() override { + // Unset the X11 error handlers. The X11 error handlers log the errors using + // a |PostTask()| on the message-loop. But since the message-loop is in the + // process of terminating, this can cause errors. + SetEmptyErrorHandlers(); + } + + void PreEarlyInitialize() override { + // Installs the X11 error handlers for the browser process used during + // startup. They simply print error messages and exit because + // we can't shutdown properly while creating and initializing services. + SetNullErrorHandlers(); + } + private: // Performs initialization steps need by both UI and GPU. void InitializeCommon(const InitParams& params) { @@ -238,7 +259,7 @@ class OzonePlatformX11 : public OzonePlatform, std::unique_ptr<OverlayManagerOzone> overlay_manager_; std::unique_ptr<InputController> input_controller_; std::unique_ptr<X11ClipboardOzone> clipboard_; - std::unique_ptr<X11CursorFactoryOzone> cursor_factory_ozone_; + std::unique_ptr<CursorFactory> cursor_factory_; std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_; // Objects in the GPU process. diff --git a/chromium/ui/ozone/platform/x11/x11_clipboard_ozone.cc b/chromium/ui/ozone/platform/x11/x11_clipboard_ozone.cc index 0f8b04c4f59..bea9cffe465 100644 --- a/chromium/ui/ozone/platform/x11/x11_clipboard_ozone.cc +++ b/chromium/ui/ozone/platform/x11/x11_clipboard_ozone.cc @@ -8,10 +8,14 @@ #include <vector> #include "base/containers/span.h" +#include "base/logging.h" #include "base/stl_util.h" #include "ui/base/clipboard/clipboard_constants.h" +#include "ui/base/x/x11_util.h" +#include "ui/gfx/x/extension_manager.h" #include "ui/gfx/x/x11_atom_cache.h" #include "ui/gfx/x/x11_types.h" +#include "ui/gfx/x/xproto.h" using base::Contains; @@ -42,13 +46,6 @@ void ExpandTypes(std::vector<std::string>* list) { list->push_back(kMimeTypeTextUtf8); } -XID FindXEventTarget(const XEvent& xev) { - XID target = xev.xany.window; - if (xev.type == GenericEvent) - target = static_cast<XIDeviceEvent*>(xev.xcookie.data)->event; - return target; -} - } // namespace // Maintains state of a single selection (aka system clipboard buffer). @@ -79,7 +76,7 @@ struct X11ClipboardOzone::SelectionState { PlatformClipboard::RequestDataClosure request_clipboard_data_callback; // The time that this instance took ownership of the clipboard. - Time acquired_selection_timestamp; + x11::Time acquired_selection_timestamp; }; X11ClipboardOzone::X11ClipboardOzone() @@ -87,32 +84,21 @@ X11ClipboardOzone::X11ClipboardOzone() atom_targets_(gfx::GetAtom(kTargets)), atom_timestamp_(gfx::GetAtom(kTimestamp)), x_property_(gfx::GetAtom(kChromeSelection)), - x_display_(gfx::GetXDisplay()), - x_window_(XCreateSimpleWindow(x_display_, - DefaultRootWindow(x_display_), - /*x=*/-100, - /*y=*/-100, - /*width=*/10, - /*height=*/10, - /*border_width=*/0, - /*border=*/0, - /*background=*/0)) { - int ignored; // xfixes_error_base. - if (!XFixesQueryExtension(x_display_, &xfixes_event_base_, &ignored)) { - LOG(ERROR) << "X server does not support XFixes."; + connection_(x11::Connection::Get()), + x_window_(CreateDummyWindow("Chromium Clipboard Window")) { + if (!connection_->xfixes().present()) return; - } using_xfixes_ = true; // Register to receive standard X11 events. X11EventSource::GetInstance()->AddXEventDispatcher(this); - for (auto atom : {atom_clipboard_, XA_PRIMARY}) { + for (auto atom : {atom_clipboard_, x11::Atom::PRIMARY}) { // Register the selection state. selection_state_.emplace(atom, std::make_unique<SelectionState>()); // Register to receive XFixes notification when selection owner changes. - XFixesSelectSelectionInput(x_display_, x_window_, atom, - XFixesSetSelectionOwnerNotifyMask); + connection_->xfixes().SelectSelectionInput( + {x_window_, atom, x11::XFixes::SelectionEventMask::SetSelectionOwner}); // Prefetch the current remote clipboard contents. QueryTargets(atom); } @@ -122,21 +108,13 @@ X11ClipboardOzone::~X11ClipboardOzone() { X11EventSource::GetInstance()->RemoveXEventDispatcher(this); } -bool X11ClipboardOzone::DispatchXEvent(XEvent* xev) { - if (FindXEventTarget(*xev) != x_window_) - return false; - - switch (xev->type) { - case SelectionRequest: - return OnSelectionRequest(xev->xselectionrequest); - case SelectionNotify: - return OnSelectionNotify(xev->xselection); - } - - if (using_xfixes_ && - xev->type == xfixes_event_base_ + XFixesSetSelectionOwnerNotify) { - return OnSetSelectionOwnerNotify(xev); - } +bool X11ClipboardOzone::DispatchXEvent(x11::Event* xev) { + if (auto* request = xev->As<x11::SelectionRequestEvent>()) + return request->owner == x_window_ && OnSelectionRequest(*request); + if (auto* notify = xev->As<x11::SelectionNotifyEvent>()) + return notify->requestor == x_window_ && OnSelectionNotify(*notify); + if (auto* notify = xev->As<x11::XFixes::SelectionNotifyEvent>()) + return notify->owner == x_window_ && OnSetSelectionOwnerNotify(*notify); return false; } @@ -146,15 +124,17 @@ bool X11ClipboardOzone::DispatchXEvent(XEvent* xev) { // TIMESTAMP: Time when we took ownership of the clipboard. // <mime-type>: Mime type to receive clipboard as. bool X11ClipboardOzone::OnSelectionRequest( - const XSelectionRequestEvent& event) { + const x11::SelectionRequestEvent& event) { // The property must be set. - if (event.property == x11::None) + if (event.property == x11::Atom::None) return false; // target=TARGETS. - auto& selection_state = GetSelectionState(event.selection); + auto& selection_state = + GetSelectionState(static_cast<x11::Atom>(event.selection)); + auto target = static_cast<x11::Atom>(event.target); PlatformClipboard::DataMap& offer_data_map = selection_state.offer_data_map; - if (event.target == atom_targets_) { + if (target == atom_targets_) { std::vector<std::string> targets; // Add TIMESTAMP. targets.push_back(kTimestamp); @@ -163,26 +143,21 @@ bool X11ClipboardOzone::OnSelectionRequest( } // Expand types, then convert from string to atom. ExpandTypes(&targets); - std::vector<XAtom> atoms; - for (auto& entry : targets) { + std::vector<x11::Atom> atoms; + for (auto& entry : targets) atoms.push_back(gfx::GetAtom(entry.c_str())); - } - XChangeProperty(x_display_, event.requestor, event.property, XA_ATOM, - /*format=*/32, PropModeReplace, - reinterpret_cast<unsigned char*>(atoms.data()), - atoms.size()); + ui::SetArrayProperty(event.requestor, event.property, x11::Atom::ATOM, + atoms); - } else if (event.target == atom_timestamp_) { + } else if (target == atom_timestamp_) { // target=TIMESTAMP. - XChangeProperty(x_display_, event.requestor, event.property, XA_INTEGER, - /*format=*/32, PropModeReplace, - reinterpret_cast<unsigned char*>( - &selection_state.acquired_selection_timestamp), - 1); - + ui::SetProperty(event.requestor, event.property, x11::Atom::INTEGER, + selection_state.acquired_selection_timestamp); } else { // Send clipboard data. - char* target_name = XGetAtomName(x_display_, event.target); + std::string target_name; + if (auto reply = connection_->GetAtomName({event.target}).Sync()) + target_name = std::move(reply->name); std::string key = target_name; // Allow conversions for text/plain[;charset=utf-8] <=> [UTF8_]STRING. @@ -193,58 +168,41 @@ bool X11ClipboardOzone::OnSelectionRequest( } auto it = offer_data_map.find(key); if (it != offer_data_map.end()) { - XChangeProperty(x_display_, event.requestor, event.property, event.target, - /*format=*/8, PropModeReplace, - const_cast<unsigned char*>(it->second.data()), - it->second.size()); + ui::SetArrayProperty(event.requestor, event.property, event.target, + it->second); } - XFree(target_name); } // Notify remote peer that clipboard has been sent. - XSelectionEvent selection_event; - selection_event.type = SelectionNotify; - selection_event.display = event.display; - selection_event.requestor = event.requestor; - selection_event.selection = event.selection; - selection_event.target = event.target; - selection_event.property = event.property; - selection_event.time = event.time; - XSendEvent(x_display_, selection_event.requestor, /*propagate=*/x11::False, - /*event_mask=*/0, reinterpret_cast<XEvent*>(&selection_event)); + x11::SelectionNotifyEvent selection_event{ + .time = event.time, + .requestor = event.requestor, + .selection = event.selection, + .target = event.target, + .property = event.property, + }; + SendEvent(selection_event, selection_event.requestor, + x11::EventMask::NoEvent); return true; } // A remote peer owns the clipboard. This event is received in response to // our request for TARGETS (GetAvailableMimeTypes), or a specific mime type // (RequestClipboardData). -bool X11ClipboardOzone::OnSelectionNotify(const XSelectionEvent& event) { +bool X11ClipboardOzone::OnSelectionNotify( + const x11::SelectionNotifyEvent& event) { // GetAvailableMimeTypes. - auto& selection_state = GetSelectionState(event.selection); - if (event.target == atom_targets_) { - XAtom type; - int format; - unsigned long item_count, after; - unsigned char* data = nullptr; - - if (XGetWindowProperty(x_display_, x_window_, x_property_, - /*long_offset=*/0, - /*long_length=*/256 * sizeof(XAtom), - /*delete=*/x11::False, XA_ATOM, &type, &format, - &item_count, &after, &data) != x11::Success) { - return false; - } + auto selection = static_cast<x11::Atom>(event.selection); + auto& selection_state = GetSelectionState(selection); + if (static_cast<x11::Atom>(event.target) == atom_targets_) { + std::vector<x11::Atom> targets; + ui::GetArrayProperty(x_window_, x_property_, &targets); selection_state.mime_types.clear(); - base::span<XAtom> targets(reinterpret_cast<XAtom*>(data), item_count); for (auto target : targets) { - char* atom_name = XGetAtomName(x_display_, target); - if (atom_name) { - selection_state.mime_types.push_back(atom_name); - XFree(atom_name); - } + if (auto reply = connection_->GetAtomName({target}).Sync()) + selection_state.mime_types.push_back(std::move(reply->name)); } - XFree(data); // If we have a saved callback, invoke it now with expanded types, otherwise // guess that we will want 'text/plain' and fetch it now. @@ -255,27 +213,20 @@ bool X11ClipboardOzone::OnSelectionNotify(const XSelectionEvent& event) { .Run(std::move(result)); } else { selection_state.data_mime_type = kMimeTypeText; - ReadRemoteClipboard(event.selection); + ReadRemoteClipboard(selection); } return true; } // RequestClipboardData. - if (event.property == x_property_) { - XAtom type; - int format; - unsigned long item_count, after; - unsigned char* data; - XGetWindowProperty(x_display_, x_window_, x_property_, - /*long_offset=*/0, /*long_length=*/~0L, - /*delete=*/x11::True, AnyPropertyType, &type, &format, - &item_count, &after, &data); - if (type != x11::None && format == 8) { - std::vector<unsigned char> tmp(data, data + item_count); - selection_state.data = tmp; - } - XFree(data); + if (static_cast<x11::Atom>(event.property) == x_property_) { + x11::Atom type; + std::vector<uint8_t> data; + ui::GetArrayProperty(x_window_, x_property_, &data, &type); + ui::DeleteProperty(x_window_, x_property_); + if (type != x11::Atom::None) + selection_state.data = std::move(data); // If we have a saved callback, invoke it now, otherwise this was a prefetch // and we have already saved |data_| for the next call to @@ -292,41 +243,41 @@ bool X11ClipboardOzone::OnSelectionNotify(const XSelectionEvent& event) { return false; } -bool X11ClipboardOzone::OnSetSelectionOwnerNotify(XEvent* xev) { - XFixesSelectionNotifyEvent* event = - reinterpret_cast<XFixesSelectionNotifyEvent*>(xev); - +bool X11ClipboardOzone::OnSetSelectionOwnerNotify( + const x11::XFixes::SelectionNotifyEvent& event) { // Reset state and fetch remote clipboard if there is a new remote owner. - if (!IsSelectionOwner(BufferForSelectionAtom(event->selection))) { - auto& selection_state = GetSelectionState(event->selection); + x11::Atom selection = event.selection; + if (!IsSelectionOwner(BufferForSelectionAtom(selection))) { + auto& selection_state = GetSelectionState(selection); selection_state.mime_types.clear(); selection_state.data_mime_type.clear(); selection_state.data.clear(); - QueryTargets(event->selection); + QueryTargets(selection); } // Increase the sequence number if the callback is set. if (update_sequence_cb_) - update_sequence_cb_.Run(BufferForSelectionAtom(event->selection)); + update_sequence_cb_.Run(BufferForSelectionAtom(selection)); return true; } -XAtom X11ClipboardOzone::SelectionAtomForBuffer(ClipboardBuffer buffer) const { +x11::Atom X11ClipboardOzone::SelectionAtomForBuffer( + ClipboardBuffer buffer) const { switch (buffer) { case ClipboardBuffer::kCopyPaste: return atom_clipboard_; case ClipboardBuffer::kSelection: - return XA_PRIMARY; + return x11::Atom::PRIMARY; default: NOTREACHED(); - return x11::None; + return x11::Atom::None; } } ClipboardBuffer X11ClipboardOzone::BufferForSelectionAtom( - XAtom selection) const { - if (selection == XA_PRIMARY) + x11::Atom selection) const { + if (selection == x11::Atom::PRIMARY) return ClipboardBuffer::kSelection; if (selection == atom_clipboard_) return ClipboardBuffer::kCopyPaste; @@ -335,18 +286,18 @@ ClipboardBuffer X11ClipboardOzone::BufferForSelectionAtom( } X11ClipboardOzone::SelectionState& X11ClipboardOzone::GetSelectionState( - XAtom selection) { + x11::Atom selection) { DCHECK(Contains(selection_state_, selection)); return *selection_state_[selection]; } -void X11ClipboardOzone::QueryTargets(XAtom selection) { +void X11ClipboardOzone::QueryTargets(x11::Atom selection) { GetSelectionState(selection).mime_types.clear(); - XConvertSelection(x_display_, selection, atom_targets_, x_property_, - x_window_, x11::CurrentTime); + connection_->ConvertSelection({x_window_, selection, atom_targets_, + x_property_, x11::Time::CurrentTime}); } -void X11ClipboardOzone::ReadRemoteClipboard(XAtom selection) { +void X11ClipboardOzone::ReadRemoteClipboard(x11::Atom selection) { auto& selection_state = GetSelectionState(selection); selection_state.data.clear(); // Allow conversions for text/plain[;charset=utf-8] <=> [UTF8_]STRING. @@ -359,23 +310,24 @@ void X11ClipboardOzone::ReadRemoteClipboard(XAtom selection) { } } - XConvertSelection(x_display_, selection, gfx::GetAtom(target.c_str()), - x_property_, x_window_, x11::CurrentTime); + connection_->ConvertSelection({x_window_, selection, gfx::GetAtom(target), + x_property_, x11::Time::CurrentTime}); } void X11ClipboardOzone::OfferClipboardData( ClipboardBuffer buffer, const PlatformClipboard::DataMap& data_map, PlatformClipboard::OfferDataClosure callback) { - const XAtom selection = SelectionAtomForBuffer(buffer); + const x11::Atom selection = SelectionAtomForBuffer(buffer); auto& selection_state = GetSelectionState(selection); - const auto timestamp = X11EventSource::GetInstance()->GetTimestamp(); + const auto timestamp = + static_cast<x11::Time>(X11EventSource::GetInstance()->GetTimestamp()); selection_state.acquired_selection_timestamp = timestamp; selection_state.offer_data_map = data_map; // Only take ownership if we are using xfixes. // TODO(joelhockey): Make clipboard work without xfixes. if (using_xfixes_) { - XSetSelectionOwner(x_display_, selection, x_window_, timestamp); + connection_->SetSelectionOwner({x_window_, selection, timestamp}); } std::move(callback).Run(); } @@ -385,7 +337,7 @@ void X11ClipboardOzone::RequestClipboardData( const std::string& mime_type, PlatformClipboard::DataMap* data_map, PlatformClipboard::RequestDataClosure callback) { - const XAtom selection = SelectionAtomForBuffer(buffer); + const x11::Atom selection = SelectionAtomForBuffer(buffer); auto& selection_state = GetSelectionState(selection); // If we are not using xfixes, return empty data. // TODO(joelhockey): Make clipboard work without xfixes. @@ -408,7 +360,7 @@ void X11ClipboardOzone::RequestClipboardData( void X11ClipboardOzone::GetAvailableMimeTypes( ClipboardBuffer buffer, PlatformClipboard::GetMimeTypesClosure callback) { - const XAtom selection = SelectionAtomForBuffer(buffer); + const x11::Atom selection = SelectionAtomForBuffer(buffer); auto& selection_state = GetSelectionState(selection); // If we are not using xfixes, return empty data. // TODO(joelhockey): Make clipboard work without xfixes. @@ -432,8 +384,9 @@ bool X11ClipboardOzone::IsSelectionOwner(ClipboardBuffer buffer) { if (!using_xfixes_) return true; - return XGetSelectionOwner(x_display_, SelectionAtomForBuffer(buffer)) == - x_window_; + auto reply = + connection_->GetSelectionOwner({SelectionAtomForBuffer(buffer)}).Sync(); + return reply && reply->owner == x_window_; } void X11ClipboardOzone::SetSequenceNumberUpdateCb( diff --git a/chromium/ui/ozone/platform/x11/x11_clipboard_ozone.h b/chromium/ui/ozone/platform/x11/x11_clipboard_ozone.h index 8743c6cc53a..478205cd472 100644 --- a/chromium/ui/ozone/platform/x11/x11_clipboard_ozone.h +++ b/chromium/ui/ozone/platform/x11/x11_clipboard_ozone.h @@ -11,8 +11,11 @@ #include "base/callback.h" #include "base/containers/flat_map.h" #include "ui/events/platform/x11/x11_event_source.h" +#include "ui/gfx/x/event.h" #include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11_types.h" +#include "ui/gfx/x/xfixes.h" +#include "ui/gfx/x/xproto.h" #include "ui/ozone/public/platform_clipboard.h" namespace ui { @@ -51,61 +54,59 @@ class X11ClipboardOzone : public PlatformClipboard, public XEventDispatcher { struct SelectionState; // XEventDispatcher: - bool DispatchXEvent(XEvent* xev) override; + bool DispatchXEvent(x11::Event* xev) override; - bool OnSelectionRequest(const XSelectionRequestEvent& event); - bool OnSelectionNotify(const XSelectionEvent& event); - bool OnSetSelectionOwnerNotify(XEvent* xev); + bool OnSelectionRequest(const x11::SelectionRequestEvent& event); + bool OnSelectionNotify(const x11::SelectionNotifyEvent& event); + bool OnSetSelectionOwnerNotify( + const x11::XFixes::SelectionNotifyEvent& event); // Returns an X atom for a clipboard buffer type. - XAtom SelectionAtomForBuffer(ClipboardBuffer buffer) const; + x11::Atom SelectionAtomForBuffer(ClipboardBuffer buffer) const; // Returns a clipboard buffer type for an X atom for a selection name of the // system clipboard buffer. - ClipboardBuffer BufferForSelectionAtom(XAtom selection) const; + ClipboardBuffer BufferForSelectionAtom(x11::Atom selection) const; // Returns the state for the given selection; - SelectionState& GetSelectionState(XAtom selection); + SelectionState& GetSelectionState(x11::Atom selection); // Queries the current clipboard owner for what mime types are available by // sending XConvertSelection with target=TARGETS. After sending this, we // will receive a SelectionNotify event with xselection.target=TARGETS which // is processed in |OnSelectionNotify|. - void QueryTargets(XAtom selection); + void QueryTargets(x11::Atom selection); // Reads the contents of the remote clipboard by sending XConvertSelection // with target=<mime-type>. After sending this, we will receive a // SelectionNotify event with xselection.target=<mime-type> which is processed // in |OnSelectionNotify|. - void ReadRemoteClipboard(XAtom selection); + void ReadRemoteClipboard(x11::Atom selection); // Local cache of atoms. - const XAtom atom_clipboard_; - const XAtom atom_targets_; - const XAtom atom_timestamp_; + const x11::Atom atom_clipboard_; + const x11::Atom atom_targets_; + const x11::Atom atom_timestamp_; // The property on |x_window_| which will receive remote clipboard contents. - const XAtom x_property_; + const x11::Atom x_property_; // Our X11 state. - Display* const x_display_; + x11::Connection* connection_; // Input-only window used as a selection owner. - const XID x_window_; + const x11::Window x_window_; // If XFixes is unavailable, this clipboard window will not register to // receive events and no processing will take place. // TODO(joelhockey): Make clipboard work without xfixes. bool using_xfixes_ = false; - // The event base returned by XFixesQueryExtension(). - int xfixes_event_base_; - // Notifies whenever clipboard sequence number is changed. PlatformClipboard::SequenceNumberUpdateCb update_sequence_cb_; // State of selections served by this instance. - base::flat_map<XAtom, std::unique_ptr<SelectionState>> selection_state_; + base::flat_map<x11::Atom, std::unique_ptr<SelectionState>> selection_state_; DISALLOW_COPY_AND_ASSIGN(X11ClipboardOzone); }; diff --git a/chromium/ui/ozone/platform/x11/x11_cursor_factory_ozone.cc b/chromium/ui/ozone/platform/x11/x11_cursor_factory_ozone.cc deleted file mode 100644 index 1b9b47ff5f9..00000000000 --- a/chromium/ui/ozone/platform/x11/x11_cursor_factory_ozone.cc +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/ozone/platform/x11/x11_cursor_factory_ozone.h" - -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/cursor/cursor_lookup.h" -#include "ui/base/cursor/cursors_aura.h" -#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" -#include "ui/gfx/geometry/point.h" - -namespace ui { - -namespace { - -X11CursorOzone* ToX11CursorOzone(PlatformCursor cursor) { - return static_cast<X11CursorOzone*>(cursor); -} - -PlatformCursor ToPlatformCursor(X11CursorOzone* cursor) { - return static_cast<PlatformCursor>(cursor); -} - -// Gets default aura cursor bitmap/hotspot and creates a X11CursorOzone with it. -scoped_refptr<X11CursorOzone> CreateAuraX11Cursor(mojom::CursorType type) { - Cursor cursor(type); - cursor.set_image_scale_factor(1); - SkBitmap bitmap = GetCursorBitmap(cursor); - gfx::Point hotspot = GetCursorHotspot(cursor); - if (!bitmap.isNull()) - return new X11CursorOzone(bitmap, hotspot); - return nullptr; -} - -} // namespace - -X11CursorFactoryOzone::X11CursorFactoryOzone() - : invisible_cursor_(X11CursorOzone::CreateInvisible()) {} - -X11CursorFactoryOzone::~X11CursorFactoryOzone() {} - -PlatformCursor X11CursorFactoryOzone::GetDefaultCursor(mojom::CursorType type) { - return ToPlatformCursor(GetDefaultCursorInternal(type).get()); -} - -PlatformCursor X11CursorFactoryOzone::CreateImageCursor( - const SkBitmap& bitmap, - const gfx::Point& hotspot, - float bitmap_dpi) { - // There is a problem with custom cursors that have no custom data. The - // resulting SkBitmap is empty and X crashes when creating a zero size cursor - // image. Return invisible cursor here instead. - if (bitmap.drawsNothing()) { - // The result of |invisible_cursor_| is owned by the caller, and will be - // Unref()ed by code far away. (Usually in web_cursor.cc in content, among - // others.) If we don't manually add another reference before we cast this - // to a void*, we can end up with |invisible_cursor_| being freed out from - // under us. - invisible_cursor_->AddRef(); - return ToPlatformCursor(invisible_cursor_.get()); - } - - X11CursorOzone* cursor = new X11CursorOzone(bitmap, hotspot); - cursor->AddRef(); - return ToPlatformCursor(cursor); -} - -PlatformCursor X11CursorFactoryOzone::CreateAnimatedCursor( - const std::vector<SkBitmap>& bitmaps, - const gfx::Point& hotspot, - int frame_delay_ms, - float bitmap_dpi) { - X11CursorOzone* cursor = new X11CursorOzone(bitmaps, hotspot, frame_delay_ms); - cursor->AddRef(); - return ToPlatformCursor(cursor); -} - -void X11CursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { - ToX11CursorOzone(cursor)->AddRef(); -} - -void X11CursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { - ToX11CursorOzone(cursor)->Release(); -} - -scoped_refptr<X11CursorOzone> X11CursorFactoryOzone::GetDefaultCursorInternal( - mojom::CursorType type) { - if (type == mojom::CursorType::kNone) - return invisible_cursor_; - - if (!default_cursors_.count(type)) { - // First try to load a predefined X11 cursor. - auto cursor = - base::MakeRefCounted<X11CursorOzone>(CursorCssNameFromId(type)); - if (cursor->xcursor() != x11::None) { - default_cursors_[type] = cursor; - return cursor; - } - - // Loads the default aura cursor bitmap for cursor type. Falls back on - // pointer cursor then invisible cursor if this fails. - cursor = CreateAuraX11Cursor(type); - if (!cursor.get()) { - if (type != mojom::CursorType::kPointer) { - cursor = GetDefaultCursorInternal(mojom::CursorType::kPointer); - } else { - NOTREACHED() << "Failed to load default cursor bitmap"; - } - } - default_cursors_[type] = cursor; - } - - // Returns owned default cursor for this type. - return default_cursors_[type]; -} - -} // namespace ui diff --git a/chromium/ui/ozone/platform/x11/x11_cursor_factory_ozone.h b/chromium/ui/ozone/platform/x11/x11_cursor_factory_ozone.h deleted file mode 100644 index 76efeeb526d..00000000000 --- a/chromium/ui/ozone/platform/x11/x11_cursor_factory_ozone.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_OZONE_PLATFORM_X11_X11_CURSOR_FACTORY_OZONE_H_ -#define UI_OZONE_PLATFORM_X11_X11_CURSOR_FACTORY_OZONE_H_ - -#include <map> -#include <memory> -#include <vector> - -#include "base/macros.h" -#include "ui/base/cursor/cursor.h" -#include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" -#include "ui/gfx/x/x11.h" -#include "ui/ozone/platform/x11/x11_cursor_ozone.h" -#include "ui/ozone/public/cursor_factory_ozone.h" - -namespace ui { - -// CursorFactoryOzone implementation for X11 cursors. -class X11CursorFactoryOzone : public CursorFactoryOzone { - public: - X11CursorFactoryOzone(); - ~X11CursorFactoryOzone() override; - - // CursorFactoryOzone: - PlatformCursor GetDefaultCursor(mojom::CursorType type) override; - PlatformCursor CreateImageCursor(const SkBitmap& bitmap, - const gfx::Point& hotspot, - float bitmap_dpi) override; - PlatformCursor CreateAnimatedCursor(const std::vector<SkBitmap>& bitmaps, - const gfx::Point& hotspot, - int frame_delay_ms, - float bitmap_dpi) override; - void RefImageCursor(PlatformCursor cursor) override; - void UnrefImageCursor(PlatformCursor cursor) override; - - private: - // Loads/caches default cursor or returns cached version. - scoped_refptr<X11CursorOzone> GetDefaultCursorInternal( - mojom::CursorType type); - - // Holds a single instance of the invisible cursor. X11 has no way to hide - // the cursor so an invisible cursor mimics that. - scoped_refptr<X11CursorOzone> invisible_cursor_; - - std::map<mojom::CursorType, scoped_refptr<X11CursorOzone>> default_cursors_; - - DISALLOW_COPY_AND_ASSIGN(X11CursorFactoryOzone); -}; - -} // namespace ui - -#endif // UI_OZONE_PLATFORM_X11_X11_CURSOR_FACTORY_OZONE_H_ diff --git a/chromium/ui/ozone/platform/x11/x11_cursor_factory_ozone_unittest.cc b/chromium/ui/ozone/platform/x11/x11_cursor_factory_ozone_unittest.cc deleted file mode 100644 index 8b065eb100b..00000000000 --- a/chromium/ui/ozone/platform/x11/x11_cursor_factory_ozone_unittest.cc +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/ozone/platform/x11/x11_cursor_factory_ozone.h" - -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/gfx/geometry/point.h" - -namespace ui { - -TEST(X11CursorFactoryOzoneTest, InvisibleRefcount) { - X11CursorFactoryOzone factory; - - // Building an image cursor with an invalid SkBitmap should return the - // invisible cursor in X11. The invisible cursor instance should have more - // than a single reference since the factory should hold a reference and - // CreateImageCursor should return an incremented refcount. - X11CursorOzone* invisible_cursor = static_cast<X11CursorOzone*>( - factory.CreateImageCursor(SkBitmap(), gfx::Point(), 1.0f)); - ASSERT_FALSE(invisible_cursor->HasOneRef()); - - // Release our refcount on the cursor - factory.UnrefImageCursor(invisible_cursor); - - // The invisible cursor should still exist. - EXPECT_TRUE(invisible_cursor->HasOneRef()); -} - -} // namespace ui diff --git a/chromium/ui/ozone/platform/x11/x11_cursor_ozone.cc b/chromium/ui/ozone/platform/x11/x11_cursor_ozone.cc deleted file mode 100644 index 64eb043d301..00000000000 --- a/chromium/ui/ozone/platform/x11/x11_cursor_ozone.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/ozone/platform/x11/x11_cursor_ozone.h" - -#include "base/check_op.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/x/x11_util.h" -#include "ui/gfx/geometry/point.h" -#include "ui/gfx/x/x11.h" - -namespace ui { - -X11CursorOzone::X11CursorOzone(const SkBitmap& bitmap, - const gfx::Point& hotspot) { - XcursorImage* image = SkBitmapToXcursorImage(bitmap, hotspot); - xcursor_ = XcursorImageLoadCursor(gfx::GetXDisplay(), image); - XcursorImageDestroy(image); -} - -X11CursorOzone::X11CursorOzone(const std::vector<SkBitmap>& bitmaps, - const gfx::Point& hotspot, - int frame_delay_ms) { - // Initialize an XCursorImage for each frame, store all of them in - // XCursorImages and load the cursor from that. - XcursorImages* images = XcursorImagesCreate(bitmaps.size()); - images->nimage = bitmaps.size(); - for (size_t frame = 0; frame < bitmaps.size(); ++frame) { - XcursorImage* x_image = SkBitmapToXcursorImage(bitmaps[frame], hotspot); - x_image->delay = frame_delay_ms; - images->images[frame] = x_image; - } - - xcursor_ = XcursorImagesLoadCursor(gfx::GetXDisplay(), images); - XcursorImagesDestroy(images); -} - -X11CursorOzone::X11CursorOzone(const char* name) { - xcursor_ = XcursorLibraryLoadCursor(gfx::GetXDisplay(), name); -} - -// static -scoped_refptr<X11CursorOzone> X11CursorOzone::CreateInvisible() { - scoped_refptr<X11CursorOzone> invisible_ = new X11CursorOzone(); - invisible_->xcursor_ = CreateInvisibleCursor(); - return invisible_; -} - -X11CursorOzone::X11CursorOzone() {} - -X11CursorOzone::~X11CursorOzone() { - XFreeCursor(gfx::GetXDisplay(), xcursor_); -} - -} // namespace ui diff --git a/chromium/ui/ozone/platform/x11/x11_cursor_ozone.h b/chromium/ui/ozone/platform/x11/x11_cursor_ozone.h deleted file mode 100644 index 6718abae17d..00000000000 --- a/chromium/ui/ozone/platform/x11/x11_cursor_ozone.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_OZONE_PLATFORM_X11_X11_CURSOR_OZONE_H_ -#define UI_OZONE_PLATFORM_X11_X11_CURSOR_OZONE_H_ - -#include <vector> - -#include "base/macros.h" -#include "base/memory/ref_counted.h" -#include "ui/base/cursor/cursor.h" -#include "ui/gfx/x/x11.h" - -class SkBitmap; - -namespace gfx { -class Point; -} - -namespace ui { - -// Ref counted class to hold an X11 cursor resource. Clears the X11 resources -// on destruction -class X11CursorOzone : public base::RefCounted<X11CursorOzone> { - public: - // Handles creating X11 cursor resources from SkBitmap/hotspot. - X11CursorOzone(const SkBitmap& bitmap, const gfx::Point& hotspot); - X11CursorOzone(const std::vector<SkBitmap>& bitmaps, - const gfx::Point& hotspot, - int frame_delay_ms); - // Loads an X11 cursor named |name| by calling XcursorLibraryLoadCursor(). - // May end up wrapping an x11::None so validity must be checked after using - // this constructor. - explicit X11CursorOzone(const char* name); - - // Creates a new cursor that is invisible. - static scoped_refptr<X11CursorOzone> CreateInvisible(); - - XID xcursor() const { return xcursor_; } - - private: - friend class base::RefCounted<X11CursorOzone>; - - X11CursorOzone(); - ~X11CursorOzone(); - - XID xcursor_ = x11::None; - - DISALLOW_COPY_AND_ASSIGN(X11CursorOzone); -}; - -} // namespace ui - -#endif // UI_OZONE_PLATFORM_X11_X11_CURSOR_OZONE_H_ diff --git a/chromium/ui/ozone/platform/x11/x11_os_exchange_data_provider_ozone.cc b/chromium/ui/ozone/platform/x11/x11_os_exchange_data_provider_ozone.cc index 7a31cb62ec9..7ede65f0e9c 100644 --- a/chromium/ui/ozone/platform/x11/x11_os_exchange_data_provider_ozone.cc +++ b/chromium/ui/ozone/platform/x11/x11_os_exchange_data_provider_ozone.cc @@ -6,13 +6,14 @@ #include <utility> -#include "base/logging.h" +#include "base/check.h" +#include "base/notreached.h" #include "ui/base/x/selection_utils.h" namespace ui { X11OSExchangeDataProviderOzone::X11OSExchangeDataProviderOzone( - XID x_window, + x11::Window x_window, const SelectionFormatMap& selection) : XOSExchangeDataProvider(x_window, selection) {} @@ -34,13 +35,14 @@ std::unique_ptr<OSExchangeDataProvider> X11OSExchangeDataProviderOzone::Clone() return std::move(ret); } -bool X11OSExchangeDataProviderOzone::DispatchXEvent(XEvent* xev) { - if (xev->xany.window != x_window()) +bool X11OSExchangeDataProviderOzone::DispatchXEvent(x11::Event* x11_event) { + XEvent* xev = &x11_event->xlib_event(); + if (xev->xany.window != static_cast<uint32_t>(x_window())) return false; switch (xev->type) { - case SelectionRequest: - selection_owner().OnSelectionRequest(*xev); + case x11::SelectionRequestEvent::opcode: + selection_owner().OnSelectionRequest(*x11_event); return true; default: NOTIMPLEMENTED(); diff --git a/chromium/ui/ozone/platform/x11/x11_os_exchange_data_provider_ozone.h b/chromium/ui/ozone/platform/x11/x11_os_exchange_data_provider_ozone.h index 7a0637318fc..65542ea14d3 100644 --- a/chromium/ui/ozone/platform/x11/x11_os_exchange_data_provider_ozone.h +++ b/chromium/ui/ozone/platform/x11/x11_os_exchange_data_provider_ozone.h @@ -7,6 +7,7 @@ #include "ui/base/x/x11_os_exchange_data_provider.h" #include "ui/events/platform/x11/x11_event_source.h" +#include "ui/gfx/x/event.h" namespace ui { @@ -14,7 +15,7 @@ namespace ui { class X11OSExchangeDataProviderOzone : public XOSExchangeDataProvider, public XEventDispatcher { public: - X11OSExchangeDataProviderOzone(XID x_window, + X11OSExchangeDataProviderOzone(x11::Window x_window, const SelectionFormatMap& selection); X11OSExchangeDataProviderOzone(); ~X11OSExchangeDataProviderOzone() override; @@ -27,7 +28,7 @@ class X11OSExchangeDataProviderOzone : public XOSExchangeDataProvider, std::unique_ptr<OSExchangeDataProvider> Clone() const override; // XEventDispatcher: - bool DispatchXEvent(XEvent* xev) override; + bool DispatchXEvent(x11::Event* xev) override; }; } // namespace ui diff --git a/chromium/ui/ozone/platform/x11/x11_screen_ozone.cc b/chromium/ui/ozone/platform/x11/x11_screen_ozone.cc index 5e9cf05b0a3..76aeb9e1c14 100644 --- a/chromium/ui/ozone/platform/x11/x11_screen_ozone.cc +++ b/chromium/ui/ozone/platform/x11/x11_screen_ozone.cc @@ -10,8 +10,9 @@ #include "ui/events/platform/x11/x11_event_source.h" #include "ui/gfx/font_render_params.h" #include "ui/gfx/geometry/dip_util.h" -#include "ui/ozone/platform/x11/x11_window_ozone.h" +#include "ui/gfx/native_widget_types.h" #include "ui/platform_window/x11/x11_topmost_window_finder.h" +#include "ui/platform_window/x11/x11_window.h" #include "ui/platform_window/x11/x11_window_manager.h" namespace ui { @@ -86,14 +87,15 @@ gfx::Point X11ScreenOzone::GetCursorScreenPoint() const { gfx::AcceleratedWidget X11ScreenOzone::GetAcceleratedWidgetAtScreenPoint( const gfx::Point& point) const { X11TopmostWindowFinder finder; - return finder.FindWindowAt(point); + return static_cast<gfx::AcceleratedWidget>(finder.FindWindowAt(point)); } gfx::AcceleratedWidget X11ScreenOzone::GetLocalProcessWidgetAtPoint( const gfx::Point& point, const std::set<gfx::AcceleratedWidget>& ignore) const { X11TopmostWindowFinder finder; - return finder.FindLocalProcessWindowAt(point, ignore); + return static_cast<gfx::AcceleratedWidget>( + finder.FindLocalProcessWindowAt(point, ignore)); } display::Display X11ScreenOzone::GetDisplayNearestPoint( @@ -125,7 +127,7 @@ std::string X11ScreenOzone::GetCurrentWorkspace() { return x11_display_manager_->GetCurrentWorkspace(); } -bool X11ScreenOzone::DispatchXEvent(XEvent* xev) { +bool X11ScreenOzone::DispatchXEvent(x11::Event* xev) { return x11_display_manager_->ProcessEvent(xev); } diff --git a/chromium/ui/ozone/platform/x11/x11_screen_ozone.h b/chromium/ui/ozone/platform/x11/x11_screen_ozone.h index 02806ba53fc..de7d392d17b 100644 --- a/chromium/ui/ozone/platform/x11/x11_screen_ozone.h +++ b/chromium/ui/ozone/platform/x11/x11_screen_ozone.h @@ -14,6 +14,7 @@ #include "ui/base/x/x11_display_manager.h" #include "ui/events/platform/x11/x11_event_source.h" #include "ui/gfx/geometry/point.h" +#include "ui/gfx/x/event.h" #include "ui/ozone/public/platform_screen.h" namespace ui { @@ -51,7 +52,7 @@ class X11ScreenOzone : public PlatformScreen, std::string GetCurrentWorkspace() override; // Overridden from ui::XEventDispatcher: - bool DispatchXEvent(XEvent* event) override; + bool DispatchXEvent(x11::Event* event) override; private: friend class X11ScreenOzoneTest; diff --git a/chromium/ui/ozone/platform/x11/x11_screen_ozone_unittest.cc b/chromium/ui/ozone/platform/x11/x11_screen_ozone_unittest.cc index 121a6ccc77c..5b2ac245341 100644 --- a/chromium/ui/ozone/platform/x11/x11_screen_ozone_unittest.cc +++ b/chromium/ui/ozone/platform/x11/x11_screen_ozone_unittest.cc @@ -13,10 +13,10 @@ #include "ui/display/display.h" #include "ui/display/display_observer.h" #include "ui/events/platform/x11/x11_event_source.h" -#include "ui/ozone/platform/x11/x11_window_ozone.h" #include "ui/ozone/test/mock_platform_window_delegate.h" #include "ui/platform_window/platform_window_delegate.h" #include "ui/platform_window/platform_window_init_properties.h" +#include "ui/platform_window/x11/x11_window.h" #include "ui/platform_window/x11/x11_window_manager.h" using ::testing::_; @@ -95,14 +95,14 @@ class X11ScreenOzoneTest : public testing::Test { manager->displays_); } - std::unique_ptr<X11WindowOzone> CreatePlatformWindow( + std::unique_ptr<X11Window> CreatePlatformWindow( MockPlatformWindowDelegate* delegate, const gfx::Rect& bounds, gfx::AcceleratedWidget* widget = nullptr) { EXPECT_CALL(*delegate, OnAcceleratedWidgetAvailable(_)) .WillOnce(StoreWidget(widget)); PlatformWindowInitProperties init_params(bounds); - auto window = std::make_unique<X11WindowOzone>(delegate); + auto window = std::make_unique<X11Window>(delegate); window->Initialize(std::move(init_params)); return window; } diff --git a/chromium/ui/ozone/platform/x11/x11_surface_factory.cc b/chromium/ui/ozone/platform/x11/x11_surface_factory.cc index a0daef0e754..d747464e40f 100644 --- a/chromium/ui/ozone/platform/x11/x11_surface_factory.cc +++ b/chromium/ui/ozone/platform/x11/x11_surface_factory.cc @@ -43,7 +43,8 @@ class GLOzoneEGLX11 : public GLOzoneEGL { base::MakeRefCounted<GLSurfaceEglReadbackX11>(window)); } else { return gl::InitializeGLSurface( - base::MakeRefCounted<gl::NativeViewGLSurfaceEGLX11GLES2>(window)); + base::MakeRefCounted<gl::NativeViewGLSurfaceEGLX11GLES2>( + static_cast<x11::Window>(window))); } } diff --git a/chromium/ui/ozone/platform/x11/x11_window_ozone.cc b/chromium/ui/ozone/platform/x11/x11_window_ozone.cc deleted file mode 100644 index 66658dc1d92..00000000000 --- a/chromium/ui/ozone/platform/x11/x11_window_ozone.cc +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/ozone/platform/x11/x11_window_ozone.h" - -#include "ui/base/dragdrop/os_exchange_data.h" -#include "ui/base/x/x11_os_exchange_data_provider.h" -#include "ui/base/x/x11_pointer_grab.h" -#include "ui/base/x/x11_topmost_window_finder.h" -#include "ui/events/event.h" -#include "ui/events/platform/scoped_event_dispatcher.h" -#include "ui/events/platform/x11/x11_event_source.h" -#include "ui/events/x/x11_window_event_manager.h" -#include "ui/ozone/platform/x11/x11_cursor_ozone.h" -#include "ui/platform_window/platform_window_delegate.h" -#include "ui/platform_window/platform_window_handler/wm_drop_handler.h" -#include "ui/platform_window/x11/x11_topmost_window_finder.h" -#include "ui/platform_window/x11/x11_window_manager.h" - -namespace ui { - -X11WindowOzone::X11WindowOzone(PlatformWindowDelegate* delegate) - : X11Window(delegate) {} - -X11WindowOzone::~X11WindowOzone() = default; - -void X11WindowOzone::SetCursor(PlatformCursor cursor) { - X11CursorOzone* cursor_ozone = static_cast<X11CursorOzone*>(cursor); - XWindow::SetCursor(cursor_ozone->xcursor()); -} - -void X11WindowOzone::Initialize(PlatformWindowInitProperties properties) { - X11Window::Initialize(std::move(properties)); - // Set a class property key that allows |this| to be used for drag action. - SetWmDragHandler(this, this); - - drag_drop_client_ = - std::make_unique<XDragDropClient>(this, display(), window()); -} - -void X11WindowOzone::StartDrag(const ui::OSExchangeData& data, - int operation, - gfx::NativeCursor cursor, - base::OnceCallback<void(int)> callback) { - DCHECK(drag_drop_client_); - - end_drag_callback_ = std::move(callback); - drag_drop_client_->InitDrag(operation, &data); - - SetCapture(); - - dragging_ = true; -} - -std::unique_ptr<ui::XTopmostWindowFinder> X11WindowOzone::CreateWindowFinder() { - return std::make_unique<X11TopmostWindowFinder>(); -} - -int X11WindowOzone::UpdateDrag(const gfx::Point& screen_point) { - WmDropHandler* drop_handler = GetWmDropHandler(*this); - if (!drop_handler) - return ui::DragDropTypes::DRAG_NONE; - // TODO: calculate the appropriate drag operation here. - return drop_handler->OnDragMotion(gfx::PointF(screen_point), - ui::DragDropTypes::DRAG_COPY); -} - -void X11WindowOzone::UpdateCursor( - ui::DragDropTypes::DragOperation negotiated_operation) { - NOTIMPLEMENTED_LOG_ONCE(); -} - -void X11WindowOzone::OnBeginForeignDrag(XID window) { - NOTIMPLEMENTED_LOG_ONCE(); -} - -void X11WindowOzone::OnEndForeignDrag() { - NOTIMPLEMENTED_LOG_ONCE(); -} - -void X11WindowOzone::OnBeforeDragLeave() { - NOTIMPLEMENTED_LOG_ONCE(); -} - -int X11WindowOzone::PerformDrop() { - WmDropHandler* drop_handler = GetWmDropHandler(*this); - if (!drop_handler) - return ui::DragDropTypes::DRAG_NONE; - - DCHECK(drag_drop_client_); - auto* target_current_context = drag_drop_client_->target_current_context(); - DCHECK(target_current_context); - - int drag_operation = ui::DragDropTypes::DRAG_NONE; - - drop_handler->OnDragDrop(std::make_unique<ui::OSExchangeData>( - std::make_unique<ui::XOSExchangeDataProvider>( - drag_drop_client_->xwindow(), - target_current_context->fetched_targets()))); - return drag_operation; -} - -void X11WindowOzone::EndMoveLoop() { - std::move(end_drag_callback_).Run(0); -} - -bool X11WindowOzone::DispatchDraggingUiEvent(ui::Event* event) { - // Drag and drop have a priority over other processing. - if (dragging_) { - DCHECK(drag_drop_client_); - - switch (event->type()) { - case ui::ET_MOUSE_MOVED: - case ui::ET_MOUSE_DRAGGED: { - drag_drop_client_->HandleMouseMovement( - event->AsLocatedEvent()->root_location(), - event->AsMouseEvent()->flags(), - event->AsMouseEvent()->time_stamp()); - return true; - } - case ui::ET_MOUSE_RELEASED: - if (!event->AsMouseEvent()->IsLeftMouseButton()) - break; - // Assume that drags are being done with the left mouse button. Only - // break the drag if the left mouse button was released. - drag_drop_client_->HandleMouseReleased(); - dragging_ = false; - ReleaseCapture(); - return true; - case ui::ET_KEY_PRESSED: - if (event->AsKeyEvent()->key_code() != ui::VKEY_ESCAPE) - break; - EndMoveLoop(); - drag_drop_client_->HandleMoveLoopEnded(); - dragging_ = false; - ReleaseCapture(); - return true; - default: - break; - } - } - return false; -} - -void X11WindowOzone::OnXWindowSelectionEvent(XEvent* xev) { - X11Window::OnXWindowSelectionEvent(xev); - DCHECK(drag_drop_client_); - drag_drop_client_->OnSelectionNotify(xev->xselection); -} - -void X11WindowOzone::OnXWindowDragDropEvent(XEvent* xev) { - X11Window::OnXWindowDragDropEvent(xev); - DCHECK(drag_drop_client_); - drag_drop_client_->HandleXdndEvent(xev->xclient); -} - -} // namespace ui diff --git a/chromium/ui/ozone/platform/x11/x11_window_ozone.h b/chromium/ui/ozone/platform/x11/x11_window_ozone.h deleted file mode 100644 index 3e2a83fe42d..00000000000 --- a/chromium/ui/ozone/platform/x11/x11_window_ozone.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_OZONE_PLATFORM_X11_X11_WINDOW_OZONE_H_ -#define UI_OZONE_PLATFORM_X11_X11_WINDOW_OZONE_H_ - -#include "ui/base/x/x11_drag_drop_client.h" -#include "ui/platform_window/platform_window_handler/wm_drag_handler.h" -#include "ui/platform_window/x11/x11_window.h" - -namespace ui { - -class PlatformWindowDelegate; - -// PlatformWindow implementation for non-ChromeOS X11 Ozone. -// PlatformEvents are ui::Events. -class X11WindowOzone : public X11Window, - public WmDragHandler, - public XDragDropClient::Delegate { - public: - explicit X11WindowOzone(PlatformWindowDelegate* delegate); - ~X11WindowOzone() override; - - X11WindowOzone(const X11WindowOzone&) = delete; - X11WindowOzone& operator=(const X11WindowOzone&) = delete; - - // Overridden from PlatformWindow: - void SetCursor(PlatformCursor cursor) override; - - // Overridden from X11Window: - void Initialize(PlatformWindowInitProperties properties) override; - - private: - // WmDragHandler - void StartDrag(const ui::OSExchangeData& data, - int operation, - gfx::NativeCursor cursor, - base::OnceCallback<void(int)> callback) override; - - // ui::XDragDropClient::Delegate - std::unique_ptr<ui::XTopmostWindowFinder> CreateWindowFinder() override; - int UpdateDrag(const gfx::Point& screen_point) override; - void UpdateCursor( - ui::DragDropTypes::DragOperation negotiated_operation) override; - void OnBeginForeignDrag(XID window) override; - void OnEndForeignDrag() override; - void OnBeforeDragLeave() override; - int PerformDrop() override; - void EndMoveLoop() override; - - // X11Window: - bool DispatchDraggingUiEvent(ui::Event* event) override; - void OnXWindowSelectionEvent(XEvent* xev) override; - void OnXWindowDragDropEvent(XEvent* xev) override; - - // True while the drag initiated in this window is in progress. - bool dragging_ = false; - - std::unique_ptr<XDragDropClient> drag_drop_client_; - base::OnceCallback<void(int)> end_drag_callback_; -}; - -} // namespace ui - -#endif // UI_OZONE_PLATFORM_X11_X11_WINDOW_OZONE_H_ diff --git a/chromium/ui/ozone/platform/x11/x11_window_ozone_chromeos.cc b/chromium/ui/ozone/platform/x11/x11_window_ozone_chromeos.cc deleted file mode 100644 index d4f22451189..00000000000 --- a/chromium/ui/ozone/platform/x11/x11_window_ozone_chromeos.cc +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/ozone/platform/x11/x11_window_ozone_chromeos.h" - -#include "ui/events/event.h" -#include "ui/ozone/platform/x11/x11_cursor_ozone.h" -#include "ui/platform_window/platform_window_delegate.h" -#include "ui/platform_window/x11/x11_window_manager.h" - -namespace ui { - -X11WindowOzone::X11WindowOzone(PlatformWindowDelegate* delegate) - : X11Window(delegate) {} - -X11WindowOzone::~X11WindowOzone() = default; - -void X11WindowOzone::SetCursor(PlatformCursor cursor) { - X11CursorOzone* cursor_ozone = static_cast<X11CursorOzone*>(cursor); - XWindow::SetCursor(cursor_ozone->xcursor()); -} - -void X11WindowOzone::Initialize(PlatformWindowInitProperties properties) { - X11Window::Initialize(std::move(properties)); -} - -} // namespace ui diff --git a/chromium/ui/ozone/platform/x11/x11_window_ozone_chromeos.h b/chromium/ui/ozone/platform/x11/x11_window_ozone_chromeos.h deleted file mode 100644 index 3bcdec53c3c..00000000000 --- a/chromium/ui/ozone/platform/x11/x11_window_ozone_chromeos.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_OZONE_PLATFORM_X11_X11_WINDOW_OZONE_CHROMEOS_H_ -#define UI_OZONE_PLATFORM_X11_X11_WINDOW_OZONE_CHROMEOS_H_ - -#include "base/macros.h" -#include "ui/platform_window/x11/x11_window.h" - -namespace ui { - -class PlatformWindowDelegate; - -// PlatformWindow implementation for ChromeOS X11 Ozone. -// PlatformEvents are ui::Events. -class X11WindowOzone : public X11Window { - public: - explicit X11WindowOzone(PlatformWindowDelegate* delegate); - ~X11WindowOzone() override; - - // Overridden from PlatformWindow: - void SetCursor(PlatformCursor cursor) override; - - // Overridden from X11Window: - void Initialize(PlatformWindowInitProperties properties) override; - - DISALLOW_COPY_AND_ASSIGN(X11WindowOzone); -}; - -} // namespace ui - -#endif // UI_OZONE_PLATFORM_X11_X11_WINDOW_OZONE_CHROMEOS_H_ diff --git a/chromium/ui/ozone/platform/x11/x11_window_ozone_unittest.cc b/chromium/ui/ozone/platform/x11/x11_window_ozone_unittest.cc index e2c5fb1f609..ddf6448c669 100644 --- a/chromium/ui/ozone/platform/x11/x11_window_ozone_unittest.cc +++ b/chromium/ui/ozone/platform/x11/x11_window_ozone_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ui/ozone/platform/x11/x11_window_ozone.h" +#include "ui/platform_window/x11/x11_window.h" #include <memory> #include <utility> @@ -16,6 +16,7 @@ #include "ui/events/event.h" #include "ui/events/platform/x11/x11_event_source.h" #include "ui/events/test/events_test_utils_x11.h" +#include "ui/gfx/x/event.h" #include "ui/ozone/test/mock_platform_window_delegate.h" #include "ui/platform_window/platform_window_delegate.h" #include "ui/platform_window/platform_window_init_properties.h" @@ -45,9 +46,7 @@ ACTION_P(CloneEvent, event_ptr) { // is more than enough. class TestScreen : public display::ScreenBase { public: - TestScreen() { - ProcessDisplayChanged({}, true); - } + TestScreen() { ProcessDisplayChanged({}, true); } ~TestScreen() override = default; TestScreen(const TestScreen& screen) = delete; TestScreen& operator=(const TestScreen& screen) = delete; @@ -88,16 +87,18 @@ class X11WindowOzoneTest : public testing::Test { EXPECT_CALL(*delegate, OnAcceleratedWidgetAvailable(_)) .WillOnce(StoreWidget(widget)); PlatformWindowInitProperties init_params(bounds); - auto window = std::make_unique<X11WindowOzone>(delegate); + auto window = std::make_unique<X11Window>(delegate); window->Initialize(std::move(init_params)); return std::move(window); } - void DispatchXEvent(XEvent* event, gfx::AcceleratedWidget widget) { - DCHECK_EQ(GenericEvent, event->type); + void DispatchXEvent(x11::Event* event, gfx::AcceleratedWidget widget) { + DCHECK_EQ(x11::GeGenericEvent::opcode, event->xlib_event().type); XIDeviceEvent* device_event = - static_cast<XIDeviceEvent*>(event->xcookie.data); + static_cast<XIDeviceEvent*>(event->xlib_event().xcookie.data); device_event->event = widget; + event->As<x11::Input::DeviceEvent>()->event = + static_cast<x11::Window>(widget); event_source_->ProcessXEvent(event); } @@ -186,8 +187,8 @@ TEST_F(X11WindowOzoneTest, SendPlatformEventToCapturedWindow) { EXPECT_EQ(gfx::Point(-277, 215), event->AsLocatedEvent()->location()); } -// This test case ensures window_manager properly provides X11WindowOzone -// instances as they are created/destroyed. +// This test case ensures window_manager properly provides X11Window instances +// as they are created/destroyed. TEST_F(X11WindowOzoneTest, GetWindowFromAcceleratedWigets) { MockPlatformWindowDelegate delegate; gfx::Rect bounds(0, 0, 100, 100); @@ -225,12 +226,12 @@ TEST_F(X11WindowOzoneTest, MouseEnterAndDelete) { auto window_2 = CreatePlatformWindow(&delegate_2, bounds_2, &widget_2); EXPECT_CALL(delegate_1, OnMouseEnter()).Times(1); - window_manager()->MouseOnWindow(static_cast<X11WindowOzone*>(window_1.get())); + window_manager()->MouseOnWindow(static_cast<X11Window*>(window_1.get())); // The mouse is already on window_1, and this should not call OnMouseEnter. - window_manager()->MouseOnWindow(static_cast<X11WindowOzone*>(window_1.get())); + window_manager()->MouseOnWindow(static_cast<X11Window*>(window_1.get())); EXPECT_CALL(delegate_2, OnMouseEnter()).Times(1); - window_manager()->MouseOnWindow(static_cast<X11WindowOzone*>(window_2.get())); + window_manager()->MouseOnWindow(static_cast<X11Window*>(window_2.get())); EXPECT_EQ(window_2.get(), window_manager()->window_mouse_currently_on_for_test()); |