Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: components/exo/shell_surface.cc

Issue 2645663004: exo: Initial support for multiple displays in ARC (Closed)
Patch Set: Refactor Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/exo/shell_surface.cc
diff --git a/components/exo/shell_surface.cc b/components/exo/shell_surface.cc
index e5322a675378dc72252b64a771441b1f5d9ba7ce..961c02e3475a56526237cdb764a1f703d0c5ad70 100644
--- a/components/exo/shell_surface.cc
+++ b/components/exo/shell_surface.cc
@@ -10,8 +10,10 @@
#include "ash/common/shelf/wm_shelf.h"
#include "ash/common/wm/window_resizer.h"
#include "ash/common/wm/window_state.h"
+#include "ash/common/wm_shell.h"
#include "ash/common/wm_window.h"
#include "ash/public/cpp/shell_window_ids.h"
+#include "ash/wm/drag_window_resizer.h"
#include "ash/wm/window_state_aura.h"
#include "ash/wm/window_util.h"
#include "base/logging.h"
@@ -143,6 +145,25 @@ class CustomWindowTargeter : public aura::WindowTargeter {
DISALLOW_COPY_AND_ASSIGN(CustomWindowTargeter);
};
+class CustomWindowResizer : public ash::WindowResizer {
reveman 2017/03/06 19:02:13 Please add a class description that explains how t
Dominik Laskowski 2017/03/08 23:13:22 Done.
+ public:
+ explicit CustomWindowResizer(ash::wm::WindowState* window_state)
+ : WindowResizer(window_state), shell_(GetTarget()->GetShell()) {
+ shell_->LockCursor();
+ }
+ ~CustomWindowResizer() override { shell_->UnlockCursor(); }
+
+ // Overridden from ash::WindowResizer:
+ void Drag(const gfx::Point& location, int event_flags) override {}
+ void CompleteDrag() override {}
+ void RevertDrag() override {}
+
+ private:
+ ash::WmShell* const shell_;
+
+ DISALLOW_COPY_AND_ASSIGN(CustomWindowResizer);
+};
+
class ShellSurfaceWidget : public views::Widget {
public:
explicit ShellSurfaceWidget(ShellSurface* shell_surface)
@@ -304,6 +325,7 @@ ShellSurface::ShellSurface(Surface* surface,
can_minimize_(can_minimize),
container_(container) {
WMHelper::GetInstance()->AddActivationObserver(this);
+ WMHelper::GetInstance()->AddDisplayConfigurationObserver(this);
surface_->SetSurfaceDelegate(this);
surface_->AddSurfaceObserver(this);
surface_->window()->Show();
@@ -336,6 +358,7 @@ ShellSurface::~ShellSurface() {
widget_->CloseNow();
}
WMHelper::GetInstance()->RemoveActivationObserver(this);
+ WMHelper::GetInstance()->RemoveDisplayConfigurationObserver(this);
if (parent_)
parent_->RemoveObserver(this);
if (surface_) {
@@ -529,9 +552,9 @@ void ShellSurface::Move() {
switch (bounds_mode_) {
case BoundsMode::SHELL:
+ case BoundsMode::CLIENT:
AttemptToStartDrag(HTCAPTION);
return;
- case BoundsMode::CLIENT:
case BoundsMode::FIXED:
return;
}
@@ -998,6 +1021,14 @@ void ShellSurface::OnAccessibilityModeChanged() {
}
////////////////////////////////////////////////////////////////////////////////
+// WMHelper::DisplayConfigurationObserver overrides:
+
+void ShellSurface::OnDisplayConfigurationChanged() {
+ if (!display_config_changed_callback_.is_null())
+ display_config_changed_callback_.Run();
+}
+
+////////////////////////////////////////////////////////////////////////////////
// ui::EventHandler overrides:
void ShellSurface::OnKeyEvent(ui::KeyEvent* event) {
@@ -1006,7 +1037,8 @@ void ShellSurface::OnKeyEvent(ui::KeyEvent* event) {
return;
}
- if (event->type() == ui::ET_KEY_PRESSED &&
+ if (bounds_mode_ == BoundsMode::SHELL &&
+ event->type() == ui::ET_KEY_PRESSED &&
event->key_code() == ui::VKEY_ESCAPE) {
EndDrag(true /* revert */);
}
@@ -1035,6 +1067,9 @@ void ShellSurface::OnMouseEvent(ui::MouseEvent* event) {
switch (event->type()) {
case ui::ET_MOUSE_DRAGGED: {
+ if (bounds_mode_ == BoundsMode::CLIENT)
+ break;
+
gfx::Point location(event->location());
aura::Window::ConvertPointToTarget(widget_->GetNativeWindow(),
widget_->GetNativeWindow()->parent(),
@@ -1210,6 +1245,16 @@ void ShellSurface::Configure() {
<< pending_configs_.size();
}
+aura::Window* ShellSurface::GetDragWindow() const {
+ if (bounds_mode_ == BoundsMode::SHELL)
+ return widget_->GetNativeWindow();
+
+ if (bounds_mode_ == BoundsMode::CLIENT && surface_)
+ return surface_->window();
+
+ return nullptr;
+}
+
void ShellSurface::AttemptToStartDrag(int component) {
DCHECK(widget_);
@@ -1217,69 +1262,79 @@ void ShellSurface::AttemptToStartDrag(int component) {
if (resizer_)
return;
- if (widget_->GetNativeWindow()->HasCapture())
+ aura::Window* window = GetDragWindow();
+ if (!window || window->HasCapture())
return;
- aura::Window* root_window = widget_->GetNativeWindow()->GetRootWindow();
- gfx::Point drag_location =
- root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot();
- aura::Window::ConvertPointToTarget(
- root_window, widget_->GetNativeWindow()->parent(), &drag_location);
-
- // Set the cursor before calling CreateWindowResizer(), as that will
- // eventually call LockCursor() and prevent the cursor from changing.
- aura::client::CursorClient* cursor_client =
- aura::client::GetCursorClient(root_window);
- DCHECK(cursor_client);
+ if (bounds_mode_ == BoundsMode::SHELL) {
+ // Set the cursor before calling CreateWindowResizer(), as that will
+ // eventually call LockCursor() and prevent the cursor from changing.
+ aura::client::CursorClient* cursor_client =
+ aura::client::GetCursorClient(window->GetRootWindow());
+ DCHECK(cursor_client);
+
+ switch (component) {
+ case HTCAPTION:
+ cursor_client->SetCursor(ui::kCursorPointer);
+ break;
+ case HTTOP:
+ cursor_client->SetCursor(ui::kCursorNorthResize);
+ break;
+ case HTTOPRIGHT:
+ cursor_client->SetCursor(ui::kCursorNorthEastResize);
+ break;
+ case HTRIGHT:
+ cursor_client->SetCursor(ui::kCursorEastResize);
+ break;
+ case HTBOTTOMRIGHT:
+ cursor_client->SetCursor(ui::kCursorSouthEastResize);
+ break;
+ case HTBOTTOM:
+ cursor_client->SetCursor(ui::kCursorSouthResize);
+ break;
+ case HTBOTTOMLEFT:
+ cursor_client->SetCursor(ui::kCursorSouthWestResize);
+ break;
+ case HTLEFT:
+ cursor_client->SetCursor(ui::kCursorWestResize);
+ break;
+ case HTTOPLEFT:
+ cursor_client->SetCursor(ui::kCursorNorthWestResize);
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
- switch (component) {
- case HTCAPTION:
- cursor_client->SetCursor(ui::kCursorPointer);
- break;
- case HTTOP:
- cursor_client->SetCursor(ui::kCursorNorthResize);
- break;
- case HTTOPRIGHT:
- cursor_client->SetCursor(ui::kCursorNorthEastResize);
- break;
- case HTRIGHT:
- cursor_client->SetCursor(ui::kCursorEastResize);
- break;
- case HTBOTTOMRIGHT:
- cursor_client->SetCursor(ui::kCursorSouthEastResize);
- break;
- case HTBOTTOM:
- cursor_client->SetCursor(ui::kCursorSouthResize);
- break;
- case HTBOTTOMLEFT:
- cursor_client->SetCursor(ui::kCursorSouthWestResize);
- break;
- case HTLEFT:
- cursor_client->SetCursor(ui::kCursorWestResize);
- break;
- case HTTOPLEFT:
- cursor_client->SetCursor(ui::kCursorNorthWestResize);
- break;
- default:
- NOTREACHED();
- break;
- }
+ resizer_ = ash::CreateWindowResizer(
+ ash::WmWindow::Get(window), GetMouseLocation(), component,
+ aura::client::WINDOW_MOVE_SOURCE_MOUSE);
+ if (!resizer_)
+ return;
- resizer_ = ash::CreateWindowResizer(
- ash::WmWindow::Get(widget_->GetNativeWindow()), drag_location, component,
- aura::client::WINDOW_MOVE_SOURCE_MOUSE);
- if (!resizer_)
- return;
+ // Apply pending origin offsets and resize direction before starting a
+ // new resize operation. These can still be pending if the client has
+ // acknowledged the configure request but not yet called Commit().
+ origin_offset_ += pending_origin_offset_;
+ pending_origin_offset_ = gfx::Vector2d();
+ resize_component_ = pending_resize_component_;
+ } else {
+ DCHECK(bounds_mode_ == BoundsMode::CLIENT);
- // Apply pending origin offsets and resize direction before starting a new
- // resize operation. These can still be pending if the client has acknowledged
- // the configure request but not yet called Commit().
- origin_offset_ += pending_origin_offset_;
- pending_origin_offset_ = gfx::Vector2d();
- resize_component_ = pending_resize_component_;
+ ash::wm::WindowState* window_state =
+ ash::wm::GetWindowState(widget_->GetNativeWindow());
+ DCHECK(!window_state->drag_details());
+ DCHECK(component == HTCAPTION);
+ window_state->CreateDragDetails(GetMouseLocation(), component,
+ aura::client::WINDOW_MOVE_SOURCE_MOUSE);
+
+ // The resizer renders phantom windows, but does not move the window.
reveman 2017/03/06 19:02:13 Is it not also used for moving windows between dis
Dominik Laskowski 2017/03/08 23:13:22 True, amended.
+ resizer_.reset(ash::DragWindowResizer::Create(
+ new CustomWindowResizer(window_state), window_state));
+ }
WMHelper::GetInstance()->AddPreTargetHandler(this);
- widget_->GetNativeWindow()->SetCapture();
+ window->SetCapture();
// Notify client that resizing state has changed.
if (IsResizing())
@@ -1290,6 +1345,10 @@ void ShellSurface::EndDrag(bool revert) {
DCHECK(widget_);
DCHECK(resizer_);
+ aura::Window* window = GetDragWindow();
+ DCHECK(window);
+ DCHECK(window->HasCapture());
+
bool was_resizing = IsResizing();
if (revert)
@@ -1298,7 +1357,7 @@ void ShellSurface::EndDrag(bool revert) {
resizer_->CompleteDrag();
WMHelper::GetInstance()->RemovePreTargetHandler(this);
- widget_->GetNativeWindow()->ReleaseCapture();
+ window->ReleaseCapture();
resizer_.reset();
// Notify client that resizing state has changed.
@@ -1411,8 +1470,31 @@ void ShellSurface::UpdateWidgetBounds() {
// should not result in a configure request.
DCHECK(!ignore_window_bounds_changes_);
ignore_window_bounds_changes_ = true;
- if (widget_->GetWindowBoundsInScreen() != new_widget_bounds)
- widget_->SetBounds(new_widget_bounds);
+ const gfx::Rect widget_bounds = widget_->GetWindowBoundsInScreen();
+ if (widget_bounds != new_widget_bounds) {
+ if (bounds_mode_ != BoundsMode::CLIENT || !resizer_) {
+ widget_->SetBounds(new_widget_bounds);
+ UpdateSurfaceBounds();
+ } else {
+ // TODO(domlaskowski): Synchronize window state transitions with the
+ // client, and abort client-side dragging on transition to fullscreen.
+ LOG_IF(ERROR, widget_bounds.size() != new_widget_bounds.size())
reveman 2017/03/06 19:02:13 nit: DLOG_IF if this is something a malicious clie
Dominik Laskowski 2017/03/08 23:13:22 Done.
+ << "Window size changed during client-driven drag";
+
+ // Convert from screen to display coordinates.
+ gfx::Point origin = new_widget_bounds.origin();
+ wm::ConvertPointFromScreen(widget_->GetNativeWindow()->parent(), &origin);
+ new_widget_bounds.set_origin(origin);
+
+ // Move the window relative to the current display.
+ widget_->GetNativeWindow()->SetBounds(new_widget_bounds);
+ UpdateSurfaceBounds();
+
+ // Render phantom windows when beyond the current display.
+ resizer_->Drag(GetMouseLocation(), 0);
+ }
+ }
+
ignore_window_bounds_changes_ = false;
}
@@ -1576,4 +1658,13 @@ void ShellSurface::UpdateShadow() {
}
}
+gfx::Point ShellSurface::GetMouseLocation() const {
+ aura::Window* const root_window = widget_->GetNativeWindow()->GetRootWindow();
+ gfx::Point location =
+ root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot();
+ aura::Window::ConvertPointToTarget(
+ root_window, widget_->GetNativeWindow()->parent(), &location);
+ return location;
+}
+
} // namespace exo

Powered by Google App Engine
This is Rietveld 408576698