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) { ...@@ -282,7 +282,7 @@ void XDragDropClient::OnXdndStatus(const XClientMessageEvent& event) {
EndMoveLoop(); EndMoveLoop();
return; return;
} }
set_source_state(SourceState::kDropped); source_state_ = SourceState::kDropped;
SendXdndDrop(source_window); SendXdndDrop(source_window);
return; return;
} }
...@@ -352,6 +352,7 @@ void XDragDropClient::OnSelectionNotify(const XSelectionEvent& xselection) { ...@@ -352,6 +352,7 @@ void XDragDropClient::OnSelectionNotify(const XSelectionEvent& xselection) {
} }
void XDragDropClient::InitDrag(int operation) { void XDragDropClient::InitDrag(int operation) {
source_state_ = SourceState::kOther;
waiting_on_status_ = false; waiting_on_status_ = false;
next_position_message_.reset(); next_position_message_.reset();
status_received_since_enter_ = false; status_received_since_enter_ = false;
...@@ -404,7 +405,7 @@ void XDragDropClient::HandleMouseReleased() { ...@@ -404,7 +405,7 @@ void XDragDropClient::HandleMouseReleased() {
if (status_received_since_enter()) { if (status_received_since_enter()) {
// If we are waiting for an XdndStatus message, we need to wait for it // If we are waiting for an XdndStatus message, we need to wait for it
// to complete. // 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 // Start timer to end the move loop if the target takes too long to send
// the XdndStatus and XdndFinished messages. // the XdndStatus and XdndFinished messages.
...@@ -425,7 +426,7 @@ void XDragDropClient::HandleMouseReleased() { ...@@ -425,7 +426,7 @@ void XDragDropClient::HandleMouseReleased() {
StartEndMoveLoopTimer(); StartEndMoveLoopTimer();
// We have negotiated an action with the other end. // We have negotiated an action with the other end.
set_source_state(SourceState::kDropped); source_state_ = SourceState::kDropped;
SendXdndDrop(source_current_window()); SendXdndDrop(source_current_window());
return; return;
} }
......
...@@ -76,44 +76,52 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient { ...@@ -76,44 +76,52 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient {
XDragDropClient(const XDragDropClient&) = delete; XDragDropClient(const XDragDropClient&) = delete;
XDragDropClient& operator=(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. // Handlers and callbacks that the subclass should implement.
// Creates the window finder.
virtual std::unique_ptr<XTopmostWindowFinder> CreateWindowFinder() = 0; 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; virtual SelectionFormatMap GetFormatMap() const = 0;
// Extracts available targets from the data provider.
virtual void RetrieveTargets(std::vector<Atom>* targets) const = 0; 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. // Called when data from another application enters the window.
virtual void OnBeginForeignDrag(XID window) = 0; virtual void OnBeginForeignDrag(XID window) = 0;
// Called when data from another application is about to leave the window. // Called when data from another application is about to leave the window.
virtual void OnEndForeignDrag() = 0; virtual void OnEndForeignDrag() = 0;
virtual void UpdateCursor(
DragDropTypes::DragOperation negotiated_operation) = 0;
// Called just before the drag leaves the window. // Called just before the drag leaves the window.
virtual void OnBeforeDragLeave() = 0; 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. // Called to end the move loop that is maintained by the subclass.
virtual void EndMoveLoop() = 0; virtual void EndMoveLoop() = 0;
Display* xdisplay() const { return xdisplay_; } Display* xdisplay() const { return xdisplay_; }
XID xwindow() const { return xwindow_; } XID xwindow() const { return xwindow_; }
XID source_current_window() const { return source_current_window_; }
XID source_current_window() { return source_current_window_; }
void set_source_current_window(XID window) { void set_source_current_window(XID window) {
source_current_window_ = window; source_current_window_ = window;
} }
XDragContext* target_current_context() { XDragContext* target_current_context() {
return target_current_context_.get(); return target_current_context_.get();
} }
SourceState source_state() const { return source_state_; } 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_; } bool waiting_on_status() const { return waiting_on_status_; }
int drag_operation() const { return drag_operation_; } int drag_operation() const { return drag_operation_; }
DragDropTypes::DragOperation negotiated_operation() const { DragDropTypes::DragOperation negotiated_operation() const {
...@@ -126,9 +134,10 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient { ...@@ -126,9 +134,10 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient {
// Resets the drag state so the object is ready to handle the drag. // Resets the drag state so the object is ready to handle the drag.
void InitDrag(int operation); void InitDrag(int operation);
// Updates |current_modifier_state_| with the given set of flags.
void UpdateModifierState(int flags); void UpdateModifierState(int flags);
// Resets the drag context. // Resets the drag context. Calls |OnEndForeignDrag()| if necessary.
void ResetDragContext(); void ResetDragContext();
void StopRepeatMouseMoveTimer(); void StopRepeatMouseMoveTimer();
...@@ -163,6 +172,11 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient { ...@@ -163,6 +172,11 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient {
void SendXdndDrop(XID dest_window); void SendXdndDrop(XID dest_window);
private: 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_; Display* const xdisplay_;
const XID xwindow_; const XID xwindow_;
......
...@@ -200,46 +200,6 @@ void DesktopDragDropClientAuraX11::Init() { ...@@ -200,46 +200,6 @@ void DesktopDragDropClientAuraX11::Init() {
move_loop_ = CreateMoveLoop(this); 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( int DesktopDragDropClientAuraX11::StartDragAndDrop(
std::unique_ptr<ui::OSExchangeData> data, std::unique_ptr<ui::OSExchangeData> data,
aura::Window* root_window, aura::Window* root_window,
...@@ -253,7 +213,6 @@ int DesktopDragDropClientAuraX11::StartDragAndDrop( ...@@ -253,7 +213,6 @@ int DesktopDragDropClientAuraX11::StartDragAndDrop(
set_source_current_window(x11::None); set_source_current_window(x11::None);
DCHECK(!g_current_drag_drop_client); DCHECK(!g_current_drag_drop_client);
g_current_drag_drop_client = this; g_current_drag_drop_client = this;
set_source_state(SourceState::kOther);
InitDrag(operation); InitDrag(operation);
const ui::OSExchangeData::Provider* provider = &data->provider(); const ui::OSExchangeData::Provider* provider = &data->provider();
...@@ -397,10 +356,6 @@ std::unique_ptr<X11MoveLoop> DesktopDragDropClientAuraX11::CreateMoveLoop( ...@@ -397,10 +356,6 @@ std::unique_ptr<X11MoveLoop> DesktopDragDropClientAuraX11::CreateMoveLoop(
return base::WrapUnique(new X11WholeScreenMoveLoop(this)); return base::WrapUnique(new X11WholeScreenMoveLoop(this));
} }
void DesktopDragDropClientAuraX11::EndMoveLoop() {
move_loop_->EndMoveLoop();
}
void DesktopDragDropClientAuraX11::DragTranslate( void DesktopDragDropClientAuraX11::DragTranslate(
const gfx::Point& root_window_location, const gfx::Point& root_window_location,
std::unique_ptr<ui::OSExchangeData>* data, std::unique_ptr<ui::OSExchangeData>* data,
...@@ -472,9 +427,9 @@ void DesktopDragDropClientAuraX11::NotifyDragLeave() { ...@@ -472,9 +427,9 @@ void DesktopDragDropClientAuraX11::NotifyDragLeave() {
target_window_ = nullptr; target_window_ = nullptr;
} }
ui::SelectionFormatMap DesktopDragDropClientAuraX11::GetFormatMap() const { std::unique_ptr<ui::XTopmostWindowFinder>
return source_provider_ ? source_provider_->GetFormatMap() DesktopDragDropClientAuraX11::CreateWindowFinder() {
: ui::SelectionFormatMap(); return std::make_unique<X11TopmostWindowFinder>();
} }
int DesktopDragDropClientAuraX11::GetDragOperation( int DesktopDragDropClientAuraX11::GetDragOperation(
...@@ -492,6 +447,56 @@ int DesktopDragDropClientAuraX11::GetDragOperation( ...@@ -492,6 +447,56 @@ int DesktopDragDropClientAuraX11::GetDragOperation(
return drag_operation; 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() { int DesktopDragDropClientAuraX11::PerformDrop() {
DCHECK(target_current_context()); DCHECK(target_current_context());
...@@ -529,14 +534,8 @@ int DesktopDragDropClientAuraX11::PerformDrop() { ...@@ -529,14 +534,8 @@ int DesktopDragDropClientAuraX11::PerformDrop() {
return drag_operation; return drag_operation;
} }
void DesktopDragDropClientAuraX11::RetrieveTargets( void DesktopDragDropClientAuraX11::EndMoveLoop() {
std::vector<Atom>* targets) const { move_loop_->EndMoveLoop();
source_provider_->RetrieveTargets(targets);
}
std::unique_ptr<ui::XTopmostWindowFinder>
DesktopDragDropClientAuraX11::CreateWindowFinder() {
return std::make_unique<X11TopmostWindowFinder>();
} }
} // namespace views } // namespace views
...@@ -101,9 +101,6 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11 ...@@ -101,9 +101,6 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11
X11MoveLoopDelegate* delegate); X11MoveLoopDelegate* delegate);
private: private:
// Ends the move loop.
void EndMoveLoop() override;
// When we receive a position X11 message, we need to translate that into // When we receive a position X11 message, we need to translate that into
// the underlying aura::Window representation, as moves internal to the X11 // the underlying aura::Window representation, as moves internal to the X11
// window can cause internal drag leave and enter messages. // window can cause internal drag leave and enter messages.
...@@ -116,25 +113,18 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11 ...@@ -116,25 +113,18 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11
// then unsubscribes |target_window_| from ourselves and forgets it. // then unsubscribes |target_window_| from ourselves and forgets it.
void NotifyDragLeave(); void NotifyDragLeave();
// This returns a representation of the data we're offering in this // ui::XDragDropClient
// drag. This is done to bypass an asynchronous roundtrip with the X11 std::unique_ptr<ui::XTopmostWindowFinder> CreateWindowFinder() override;
// 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.
int GetDragOperation(const gfx::Point& screen_point) override; int GetDragOperation(const gfx::Point& screen_point) override;
int PerformDrop() override;
void OnBeginForeignDrag(XID window) override;
void OnEndForeignDrag() override;
void UpdateCursor( void UpdateCursor(
ui::DragDropTypes::DragOperation negotiated_operation) override; ui::DragDropTypes::DragOperation negotiated_operation) override;
void OnBeforeDragLeave() override; ui::SelectionFormatMap GetFormatMap() const override;
void RetrieveTargets(std::vector<Atom>* targets) const override; void RetrieveTargets(std::vector<Atom>* targets) const override;
void OnBeginForeignDrag(XID window) override;
std::unique_ptr<ui::XTopmostWindowFinder> CreateWindowFinder() 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 // A nested run loop that notifies this object of events through the
// X11MoveLoopDelegate interface. // 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