Skip to content

Commit

Permalink
chromeos: converts WindowResizer to aura::Window
Browse files Browse the repository at this point in the history
BUG=722553
TEST=covered by tests
R=msw@chromium.org

Review-Url: https://codereview.chromium.org/2897993003
Cr-Commit-Position: refs/heads/master@{#473682}
  • Loading branch information
sky authored and Commit bot committed May 22, 2017
1 parent d60b42a commit a5e9a12
Show file tree
Hide file tree
Showing 26 changed files with 273 additions and 249 deletions.
15 changes: 7 additions & 8 deletions ash/accelerators/accelerator_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,14 @@ TEST_F(AcceleratorControllerTest, WindowSnap) {

{
GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT);
gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent(
WmWindow::Get(window.get()));
gfx::Rect expected_bounds =
wm::GetDefaultLeftSnappedWindowBoundsInParent(window.get());
EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
}
{
GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT);
gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent(
WmWindow::Get(window.get()));
gfx::Rect expected_bounds =
wm::GetDefaultRightSnappedWindowBoundsInParent(window.get());
EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
}
{
Expand Down Expand Up @@ -489,8 +489,8 @@ TEST_F(AcceleratorControllerTest, TestRepeatedSnap) {
// Snap right.
GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT);
gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent();
gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent(
WmWindow::Get(window.get()));
gfx::Rect expected_bounds =
wm::GetDefaultRightSnappedWindowBoundsInParent(window.get());
EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
EXPECT_TRUE(window_state->IsSnapped());
// Snap right again ->> becomes normal.
Expand All @@ -503,8 +503,7 @@ TEST_F(AcceleratorControllerTest, TestRepeatedSnap) {
// Snap left.
GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT);
EXPECT_TRUE(window_state->IsSnapped());
expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent(
WmWindow::Get(window.get()));
expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent(window.get());
EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
// Snap left again ->> becomes normal.
GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT);
Expand Down
16 changes: 10 additions & 6 deletions ash/frame/caption_buttons/frame_size_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include "ash/wm/workspace/phantom_window_controller.h"
#include "ash/wm_window.h"
#include "base/i18n/rtl.h"
#include "ui/aura/window.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/coordinate_conversion.h"

namespace ash {

Expand Down Expand Up @@ -210,15 +212,17 @@ void FrameSizeButton::UpdateSnapType(const ui::LocatedEvent& event) {
}

if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) {
WmWindow* window = WmWindow::Get(frame_->GetNativeWindow());
if (!phantom_window_controller_.get())
phantom_window_controller_.reset(new PhantomWindowController(window));
gfx::Rect phantom_bounds_in_parent =
aura::Window* window = frame_->GetNativeWindow();
if (!phantom_window_controller_.get()) {
phantom_window_controller_.reset(
new PhantomWindowController(WmWindow::Get(window)));
}
gfx::Rect phantom_bounds_in_screen =
(snap_type_ == SNAP_LEFT)
? wm::GetDefaultLeftSnappedWindowBoundsInParent(window)
: wm::GetDefaultRightSnappedWindowBoundsInParent(window);
phantom_window_controller_->Show(
window->GetParent()->ConvertRectToScreen(phantom_bounds_in_parent));
::wm::ConvertRectToScreen(window->parent(), &phantom_bounds_in_screen);
phantom_window_controller_->Show(phantom_bounds_in_screen);
} else {
phantom_window_controller_.reset();
}
Expand Down
6 changes: 3 additions & 3 deletions ash/shelf/shelf_window_watcher_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ TEST_F(ShelfWindowWatcherTest, DragWindow) {
EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status);

// Simulate dragging of the window and check its item is not changed.
std::unique_ptr<WindowResizer> resizer(CreateWindowResizer(
WmWindow::Get(widget->GetNativeWindow()), gfx::Point(), HTCAPTION,
aura::client::WINDOW_MOVE_SOURCE_MOUSE));
std::unique_ptr<WindowResizer> resizer(
CreateWindowResizer(widget->GetNativeWindow(), gfx::Point(), HTCAPTION,
aura::client::WINDOW_MOVE_SOURCE_MOUSE));
ASSERT_TRUE(resizer.get());
resizer->Drag(gfx::Point(50, 50), 0);
resizer->CompleteDrag();
Expand Down
32 changes: 15 additions & 17 deletions ash/wm/default_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "ash/wm/window_state_util.h"
#include "ash/wm/wm_event.h"
#include "ash/wm_window.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
Expand Down Expand Up @@ -169,11 +170,11 @@ void DefaultState::OnWMEvent(WindowState* window_state, const WMEvent* event) {
}

if (next_state_type == current_state_type && window_state->IsSnapped()) {
aura::Window* window = window_state->window()->aura_window();
gfx::Rect snapped_bounds =
event->type() == WM_EVENT_SNAP_LEFT
? GetDefaultLeftSnappedWindowBoundsInParent(window_state->window())
: GetDefaultRightSnappedWindowBoundsInParent(
window_state->window());
? GetDefaultLeftSnappedWindowBoundsInParent(window)
: GetDefaultRightSnappedWindowBoundsInParent(window);
window_state->SetBoundsDirectAnimated(snapped_bounds);
return;
}
Expand Down Expand Up @@ -584,7 +585,7 @@ void DefaultState::ReenterToCurrentState(

void DefaultState::UpdateBoundsFromState(WindowState* window_state,
WindowStateType previous_state_type) {
WmWindow* window = window_state->window();
aura::Window* window = window_state->window()->aura_window();
gfx::Rect bounds_in_parent;
switch (state_type_) {
case WINDOW_STATE_TYPE_LEFT_SNAPPED:
Expand All @@ -598,7 +599,7 @@ void DefaultState::UpdateBoundsFromState(WindowState* window_state,
case WINDOW_STATE_TYPE_DEFAULT:
case WINDOW_STATE_TYPE_NORMAL: {
gfx::Rect work_area_in_parent =
ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window());
ScreenUtil::GetDisplayWorkAreaBoundsInParent(window);
if (window_state->HasRestoreBounds()) {
bounds_in_parent = window_state->GetRestoreBoundsInParent();
// Check if the |window|'s restored size is bigger than the working area
Expand All @@ -612,7 +613,7 @@ void DefaultState::UpdateBoundsFromState(WindowState* window_state,
kMaximizedWindowInset, kMaximizedWindowInset);
}
} else {
bounds_in_parent = window->GetBounds();
bounds_in_parent = window->bounds();
}
// Make sure that part of the window is always visible.
if (!window_state->is_dragged()) {
Expand All @@ -625,15 +626,13 @@ void DefaultState::UpdateBoundsFromState(WindowState* window_state,
break;
}
case WINDOW_STATE_TYPE_MAXIMIZED:
bounds_in_parent =
ScreenUtil::GetMaximizedWindowBoundsInParent(window->aura_window());
bounds_in_parent = ScreenUtil::GetMaximizedWindowBoundsInParent(window);
break;

case WINDOW_STATE_TYPE_FULLSCREEN:
case WINDOW_STATE_TYPE_PINNED:
case WINDOW_STATE_TYPE_TRUSTED_PINNED:
bounds_in_parent =
ScreenUtil::GetDisplayBoundsInParent(window->aura_window());
bounds_in_parent = ScreenUtil::GetDisplayBoundsInParent(window);
break;

case WINDOW_STATE_TYPE_MINIMIZED:
Expand Down Expand Up @@ -664,18 +663,17 @@ void DefaultState::UpdateBoundsFromState(WindowState* window_state,
if (window_state->IsMinimized()) {
// Save the previous show state so that we can correctly restore it after
// exiting the minimized mode.
window->SetPreMinimizedShowState(ToWindowShowState(previous_state_type));
window->SetVisibilityAnimationType(
WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
window->SetProperty(aura::client::kPreMinimizedShowStateKey,
ToWindowShowState(previous_state_type));
::wm::SetWindowVisibilityAnimationType(
window, WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);

// Hide the window.
window->Hide();
// Activate another window.
if (window_state->IsActive())
window_state->Deactivate();
} else if ((window->GetTargetVisibility() ||
} else if ((window->layer()->GetTargetVisibility() ||
IsMinimizedWindowState(previous_state_type)) &&
!window->GetLayerVisible()) {
!window->layer()->visible()) {
// The layer may be hidden if the window was previously minimized. Make
// sure it's visible.
window->Show();
Expand Down
4 changes: 2 additions & 2 deletions ash/wm/default_window_resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "ash/shell_port.h"
#include "ash/wm/window_state.h"
#include "ash/wm_window.h"
#include "ui/aura/window.h"

namespace ash {

Expand All @@ -22,7 +22,7 @@ DefaultWindowResizer* DefaultWindowResizer::Create(

void DefaultWindowResizer::Drag(const gfx::Point& location, int event_flags) {
gfx::Rect bounds(CalculateBoundsForDrag(location));
if (bounds != GetTarget()->GetBounds()) {
if (bounds != GetTarget()->bounds()) {
if (!did_move_or_resize_ && !details().restore_bounds.IsEmpty())
window_state_->ClearRestoreBounds();
did_move_or_resize_ = true;
Expand Down
37 changes: 16 additions & 21 deletions ash/wm/drag_window_resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void DragWindowResizer::Drag(const gfx::Point& location, int event_flags) {
// Show a phantom window for dragging in another root window.
if (display::Screen::GetScreen()->GetNumDisplays() > 1) {
gfx::Point location_in_screen = location;
::wm::ConvertPointToScreen(GetAuraTarget()->parent(), &location_in_screen);
UpdateDragWindow(GetAuraTarget()->bounds(), location_in_screen);
::wm::ConvertPointToScreen(GetTarget()->parent(), &location_in_screen);
UpdateDragWindow(GetTarget()->bounds(), location_in_screen);
} else {
drag_window_controller_.reset();
}
Expand All @@ -65,23 +65,23 @@ void DragWindowResizer::Drag(const gfx::Point& location, int event_flags) {
void DragWindowResizer::CompleteDrag() {
next_window_resizer_->CompleteDrag();

GetAuraTarget()->layer()->SetOpacity(details().initial_opacity);
GetTarget()->layer()->SetOpacity(details().initial_opacity);
drag_window_controller_.reset();

// Check if the destination is another display.
gfx::Point last_mouse_location_in_screen = last_mouse_location_;
::wm::ConvertPointToScreen(GetAuraTarget()->parent(),
::wm::ConvertPointToScreen(GetTarget()->parent(),
&last_mouse_location_in_screen);
display::Screen* screen = display::Screen::GetScreen();
const display::Display dst_display =
screen->GetDisplayNearestPoint(last_mouse_location_in_screen);

if (dst_display.id() !=
screen->GetDisplayNearestWindow(GetAuraTarget()->GetRootWindow()).id()) {
screen->GetDisplayNearestWindow(GetTarget()->GetRootWindow()).id()) {
// Adjust the size and position so that it doesn't exceed the size of
// work area.
const gfx::Size& size = dst_display.work_area().size();
gfx::Rect bounds = GetAuraTarget()->bounds();
gfx::Rect bounds = GetTarget()->bounds();
if (bounds.width() > size.width()) {
int diff = bounds.width() - size.width();
bounds.set_x(bounds.x() + diff / 2);
Expand All @@ -91,7 +91,7 @@ void DragWindowResizer::CompleteDrag() {
bounds.set_height(size.height());

gfx::Rect dst_bounds = bounds;
::wm::ConvertRectToScreen(GetAuraTarget()->parent(), &dst_bounds);
::wm::ConvertRectToScreen(GetTarget()->parent(), &dst_bounds);

// Adjust the position so that the cursor is on the window.
if (!dst_bounds.Contains(last_mouse_location_in_screen)) {
Expand All @@ -104,15 +104,15 @@ void DragWindowResizer::CompleteDrag() {
ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(dst_display.bounds(),
&dst_bounds);

GetAuraTarget()->SetBoundsInScreen(dst_bounds, dst_display);
GetTarget()->SetBoundsInScreen(dst_bounds, dst_display);
}
}

void DragWindowResizer::RevertDrag() {
next_window_resizer_->RevertDrag();

drag_window_controller_.reset();
GetAuraTarget()->layer()->SetOpacity(details().initial_opacity);
GetTarget()->layer()->SetOpacity(details().initial_opacity);
}

DragWindowResizer::DragWindowResizer(WindowResizer* next_window_resizer,
Expand All @@ -129,8 +129,7 @@ DragWindowResizer::DragWindowResizer(WindowResizer* next_window_resizer,
Shell::Get()->mouse_cursor_filter();
mouse_cursor_filter->set_mouse_warp_enabled(ShouldAllowMouseWarp());
if (ShouldAllowMouseWarp())
mouse_cursor_filter->ShowSharedEdgeIndicator(
GetAuraTarget()->GetRootWindow());
mouse_cursor_filter->ShowSharedEdgeIndicator(GetTarget()->GetRootWindow());
instance_ = this;
}

Expand All @@ -141,32 +140,28 @@ void DragWindowResizer::UpdateDragWindow(
return;

if (!drag_window_controller_)
drag_window_controller_.reset(new DragWindowController(GetAuraTarget()));
drag_window_controller_.reset(new DragWindowController(GetTarget()));

gfx::Rect bounds_in_screen = bounds_in_parent;
::wm::ConvertRectToScreen(GetAuraTarget()->parent(), &bounds_in_screen);
::wm::ConvertRectToScreen(GetTarget()->parent(), &bounds_in_screen);

gfx::Rect root_bounds_in_screen =
GetAuraTarget()->GetRootWindow()->GetBoundsInScreen();
GetTarget()->GetRootWindow()->GetBoundsInScreen();
float opacity = 1.0f;
if (!root_bounds_in_screen.Contains(drag_location_in_screen)) {
gfx::Rect visible_bounds = root_bounds_in_screen;
visible_bounds.Intersect(bounds_in_screen);
opacity = DragWindowController::GetDragWindowOpacity(bounds_in_screen,
visible_bounds);
}
GetAuraTarget()->layer()->SetOpacity(opacity);
GetTarget()->layer()->SetOpacity(opacity);
drag_window_controller_->Update(bounds_in_screen, drag_location_in_screen);
}

bool DragWindowResizer::ShouldAllowMouseWarp() {
return details().window_component == HTCAPTION &&
!::wm::GetTransientParent(GetAuraTarget()) &&
wm::IsWindowUserPositionable(GetAuraTarget());
}

aura::Window* DragWindowResizer::GetAuraTarget() {
return WmWindow::GetAuraWindow(GetTarget());
!::wm::GetTransientParent(GetTarget()) &&
wm::IsWindowUserPositionable(GetTarget());
}

} // namespace ash
2 changes: 0 additions & 2 deletions ash/wm/drag_window_resizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class ASH_EXPORT DragWindowResizer : public WindowResizer {
// Returns true if we should allow the mouse pointer to warp.
bool ShouldAllowMouseWarp();

aura::Window* GetAuraTarget();

std::unique_ptr<WindowResizer> next_window_resizer_;

// Shows a semi-transparent image of the window being dragged.
Expand Down
3 changes: 1 addition & 2 deletions ash/wm/drag_window_resizer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ class DragWindowResizerTest : public test::AshTestBase {
aura::Window* window,
const gfx::Point& point_in_parent,
int window_component) {
return CreateWindowResizer(WmWindow::Get(window), point_in_parent,
window_component,
return CreateWindowResizer(window, point_in_parent, window_component,
aura::client::WINDOW_MOVE_SOURCE_MOUSE)
.release();
}
Expand Down
2 changes: 1 addition & 1 deletion ash/wm/overview/window_selector_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ TEST_F(WindowSelectorTest, OverviewWhileDragging) {
const gfx::Rect bounds(10, 10, 100, 100);
std::unique_ptr<aura::Window> window(CreateWindow(bounds));
std::unique_ptr<WindowResizer> resizer(
CreateWindowResizer(WmWindow::Get(window.get()), gfx::Point(), HTCAPTION,
CreateWindowResizer(window.get(), gfx::Point(), HTCAPTION,
aura::client::WINDOW_MOVE_SOURCE_MOUSE));
ASSERT_TRUE(resizer.get());
gfx::Point location = resizer->GetInitialLocation();
Expand Down
Loading

0 comments on commit a5e9a12

Please sign in to comment.