Commit 56243b0d authored by Alexander Dunaev's avatar Alexander Dunaev Committed by Commit Bot

[ozone/x11] Re-arranged some code in DDDClients for Aura and X11.

This CL is purely a beautifying one, no changes to any logic are done.

Bug: 1014860
Change-Id: I6e2aa1fd125cafea70bfdcac0a077268ef4baefb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2011224
Commit-Queue: Alexander Dunaev <adunaev@igalia.com>
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Auto-Submit: Alexander Dunaev <adunaev@igalia.com>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733526}
parent 99ac01ba
......@@ -282,7 +282,7 @@ void XDragDropClient::OnXdndStatus(const XClientMessageEvent& event) {
EndMoveLoop();
return;
}
set_source_state(SourceState::kDropped);
source_state_ = SourceState::kDropped;
SendXdndDrop(source_window);
return;
}
......@@ -352,6 +352,7 @@ void XDragDropClient::OnSelectionNotify(const XSelectionEvent& xselection) {
}
void XDragDropClient::InitDrag(int operation) {
source_state_ = SourceState::kOther;
waiting_on_status_ = false;
next_position_message_.reset();
status_received_since_enter_ = false;
......@@ -404,7 +405,7 @@ void XDragDropClient::HandleMouseReleased() {
if (status_received_since_enter()) {
// If we are waiting for an XdndStatus message, we need to wait for it
// to complete.
set_source_state(SourceState::kPendingDrop);
source_state_ = SourceState::kPendingDrop;
// Start timer to end the move loop if the target takes too long to send
// the XdndStatus and XdndFinished messages.
......@@ -425,7 +426,7 @@ void XDragDropClient::HandleMouseReleased() {
StartEndMoveLoopTimer();
// We have negotiated an action with the other end.
set_source_state(SourceState::kDropped);
source_state_ = SourceState::kDropped;
SendXdndDrop(source_current_window());
return;
}
......
......@@ -76,44 +76,52 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient {
XDragDropClient(const XDragDropClient&) = delete;
XDragDropClient& operator=(const XDragDropClient&) = delete;
// We maintain a mapping of live XDragDropClient objects to their X11 windows,
// so that we'd able to short circuit sending X11 messages to windows in our
// process.
static XDragDropClient* GetForWindow(XID window);
// Handlers and callbacks that the subclass should implement.
// Creates the window finder.
virtual std::unique_ptr<XTopmostWindowFinder> CreateWindowFinder() = 0;
// Handling XdndPosition can be paused while waiting for more data; this is
// called either synchronously from OnXdndPosition, or asynchronously after
// we've received data requested from the other window.
virtual int GetDragOperation(const gfx::Point& screen_point) = 0;
// Updates the mouse cursor shape.
virtual void UpdateCursor(
DragDropTypes::DragOperation negotiated_operation) = 0;
// Returns a representation of the data we're offering in this drag. This is
// done to bypass an asynchronous roundtrip with the X11 server.
virtual SelectionFormatMap GetFormatMap() const = 0;
// Extracts available targets from the data provider.
virtual void RetrieveTargets(std::vector<Atom>* targets) const = 0;
virtual int GetDragOperation(const gfx::Point& screen_point) = 0;
// Drops data at the current location and returns the resulting operation.
virtual int PerformDrop() = 0;
// Called when data from another application enters the window.
virtual void OnBeginForeignDrag(XID window) = 0;
// Called when data from another application is about to leave the window.
virtual void OnEndForeignDrag() = 0;
virtual void UpdateCursor(
DragDropTypes::DragOperation negotiated_operation) = 0;
// Called just before the drag leaves the window.
virtual void OnBeforeDragLeave() = 0;
// Drops data at the current location and returns the resulting operation.
virtual int PerformDrop() = 0;
// Called to end the move loop that is maintained by the subclass.
virtual void EndMoveLoop() = 0;
Display* xdisplay() const { return xdisplay_; }
XID xwindow() const { return xwindow_; }
XID source_current_window() { return source_current_window_; }
XID source_current_window() const { return source_current_window_; }
void set_source_current_window(XID window) {
source_current_window_ = window;
}
XDragContext* target_current_context() {
return target_current_context_.get();
}
SourceState source_state() const { return source_state_; }
void set_source_state(SourceState state) { source_state_ = state; }
bool waiting_on_status() const { return waiting_on_status_; }
int drag_operation() const { return drag_operation_; }
DragDropTypes::DragOperation negotiated_operation() const {
......@@ -126,9 +134,10 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient {
// Resets the drag state so the object is ready to handle the drag.
void InitDrag(int operation);
// Updates |current_modifier_state_| with the given set of flags.
void UpdateModifierState(int flags);
// Resets the drag context.
// Resets the drag context. Calls |OnEndForeignDrag()| if necessary.
void ResetDragContext();
void StopRepeatMouseMoveTimer();
......@@ -163,6 +172,11 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient {
void SendXdndDrop(XID dest_window);
private:
// We maintain a mapping of live XDragDropClient objects to their X11 windows,
// so that we'd able to short circuit sending X11 messages to windows in our
// process.
static XDragDropClient* GetForWindow(XID window);
Display* const xdisplay_;
const XID xwindow_;
......
......@@ -200,46 +200,6 @@ void DesktopDragDropClientAuraX11::Init() {
move_loop_ = CreateMoveLoop(this);
}
void DesktopDragDropClientAuraX11::OnBeginForeignDrag(XID window) {
DCHECK(target_current_context());
DCHECK(!target_current_context()->source_client());
ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
source_window_events_ =
std::make_unique<ui::XScopedEventSelector>(window, PropertyChangeMask);
}
void DesktopDragDropClientAuraX11::OnEndForeignDrag() {
DCHECK(target_current_context());
DCHECK(!target_current_context()->source_client());
ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
}
void DesktopDragDropClientAuraX11::OnBeforeDragLeave() {
NotifyDragLeave();
}
void DesktopDragDropClientAuraX11::UpdateCursor(
ui::DragDropTypes::DragOperation negotiated_operation) {
ui::CursorType cursor_type = ui::CursorType::kNull;
switch (negotiated_operation) {
case ui::DragDropTypes::DRAG_NONE:
cursor_type = ui::CursorType::kDndNone;
break;
case ui::DragDropTypes::DRAG_MOVE:
cursor_type = ui::CursorType::kDndMove;
break;
case ui::DragDropTypes::DRAG_COPY:
cursor_type = ui::CursorType::kDndCopy;
break;
case ui::DragDropTypes::DRAG_LINK:
cursor_type = ui::CursorType::kDndLink;
break;
}
move_loop_->UpdateCursor(cursor_manager_->GetInitializedCursor(cursor_type));
}
int DesktopDragDropClientAuraX11::StartDragAndDrop(
std::unique_ptr<ui::OSExchangeData> data,
aura::Window* root_window,
......@@ -253,7 +213,6 @@ int DesktopDragDropClientAuraX11::StartDragAndDrop(
set_source_current_window(x11::None);
DCHECK(!g_current_drag_drop_client);
g_current_drag_drop_client = this;
set_source_state(SourceState::kOther);
InitDrag(operation);
const ui::OSExchangeData::Provider* provider = &data->provider();
......@@ -397,10 +356,6 @@ std::unique_ptr<X11MoveLoop> DesktopDragDropClientAuraX11::CreateMoveLoop(
return base::WrapUnique(new X11WholeScreenMoveLoop(this));
}
void DesktopDragDropClientAuraX11::EndMoveLoop() {
move_loop_->EndMoveLoop();
}
void DesktopDragDropClientAuraX11::DragTranslate(
const gfx::Point& root_window_location,
std::unique_ptr<ui::OSExchangeData>* data,
......@@ -472,9 +427,9 @@ void DesktopDragDropClientAuraX11::NotifyDragLeave() {
target_window_ = nullptr;
}
ui::SelectionFormatMap DesktopDragDropClientAuraX11::GetFormatMap() const {
return source_provider_ ? source_provider_->GetFormatMap()
: ui::SelectionFormatMap();
std::unique_ptr<ui::XTopmostWindowFinder>
DesktopDragDropClientAuraX11::CreateWindowFinder() {
return std::make_unique<X11TopmostWindowFinder>();
}
int DesktopDragDropClientAuraX11::GetDragOperation(
......@@ -492,6 +447,56 @@ int DesktopDragDropClientAuraX11::GetDragOperation(
return drag_operation;
}
void DesktopDragDropClientAuraX11::UpdateCursor(
ui::DragDropTypes::DragOperation negotiated_operation) {
ui::CursorType cursor_type = ui::CursorType::kNull;
switch (negotiated_operation) {
case ui::DragDropTypes::DRAG_NONE:
cursor_type = ui::CursorType::kDndNone;
break;
case ui::DragDropTypes::DRAG_MOVE:
cursor_type = ui::CursorType::kDndMove;
break;
case ui::DragDropTypes::DRAG_COPY:
cursor_type = ui::CursorType::kDndCopy;
break;
case ui::DragDropTypes::DRAG_LINK:
cursor_type = ui::CursorType::kDndLink;
break;
}
move_loop_->UpdateCursor(cursor_manager_->GetInitializedCursor(cursor_type));
}
ui::SelectionFormatMap DesktopDragDropClientAuraX11::GetFormatMap() const {
return source_provider_ ? source_provider_->GetFormatMap()
: ui::SelectionFormatMap();
}
void DesktopDragDropClientAuraX11::RetrieveTargets(
std::vector<Atom>* targets) const {
source_provider_->RetrieveTargets(targets);
}
void DesktopDragDropClientAuraX11::OnBeginForeignDrag(XID window) {
DCHECK(target_current_context());
DCHECK(!target_current_context()->source_client());
ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
source_window_events_ =
std::make_unique<ui::XScopedEventSelector>(window, PropertyChangeMask);
}
void DesktopDragDropClientAuraX11::OnEndForeignDrag() {
DCHECK(target_current_context());
DCHECK(!target_current_context()->source_client());
ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
}
void DesktopDragDropClientAuraX11::OnBeforeDragLeave() {
NotifyDragLeave();
}
int DesktopDragDropClientAuraX11::PerformDrop() {
DCHECK(target_current_context());
......@@ -529,14 +534,8 @@ int DesktopDragDropClientAuraX11::PerformDrop() {
return drag_operation;
}
void DesktopDragDropClientAuraX11::RetrieveTargets(
std::vector<Atom>* targets) const {
source_provider_->RetrieveTargets(targets);
}
std::unique_ptr<ui::XTopmostWindowFinder>
DesktopDragDropClientAuraX11::CreateWindowFinder() {
return std::make_unique<X11TopmostWindowFinder>();
void DesktopDragDropClientAuraX11::EndMoveLoop() {
move_loop_->EndMoveLoop();
}
} // namespace views
......@@ -101,9 +101,6 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11
X11MoveLoopDelegate* delegate);
private:
// Ends the move loop.
void EndMoveLoop() override;
// When we receive a position X11 message, we need to translate that into
// the underlying aura::Window representation, as moves internal to the X11
// window can cause internal drag leave and enter messages.
......@@ -116,25 +113,18 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11
// then unsubscribes |target_window_| from ourselves and forgets it.
void NotifyDragLeave();
// This returns a representation of the data we're offering in this
// drag. This is done to bypass an asynchronous roundtrip with the X11
// server.
ui::SelectionFormatMap GetFormatMap() const override;
// Handling XdndPosition can be paused while waiting for more data; this is
// called either synchronously from OnXdndPosition, or asynchronously after
// we've received data requested from the other window.
// ui::XDragDropClient
std::unique_ptr<ui::XTopmostWindowFinder> CreateWindowFinder() override;
int GetDragOperation(const gfx::Point& screen_point) override;
int PerformDrop() override;
void OnBeginForeignDrag(XID window) override;
void OnEndForeignDrag() override;
void UpdateCursor(
ui::DragDropTypes::DragOperation negotiated_operation) override;
void OnBeforeDragLeave() override;
ui::SelectionFormatMap GetFormatMap() const override;
void RetrieveTargets(std::vector<Atom>* targets) const override;
std::unique_ptr<ui::XTopmostWindowFinder> CreateWindowFinder() override;
void OnBeginForeignDrag(XID window) override;
void OnEndForeignDrag() override;
void OnBeforeDragLeave() override;
int PerformDrop() override;
void EndMoveLoop() override;
// A nested run loop that notifies this object of events through the
// X11MoveLoopDelegate interface.
......
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