[go: nahoru, domu]

blob: 901273a2177b35d1b3aaefcdf148cddcaedfe831 [file] [log] [blame]
Evan Stade1b050fed2018-09-21 21:17:171// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Evan Stadeeb42d772019-05-03 01:51:345#include "ash/frame/snap_controller_impl.h"
Evan Stade1b050fed2018-09-21 21:17:176
7#include "ash/wm/window_positioning_utils.h"
8#include "ash/wm/window_state.h"
9#include "ash/wm/wm_event.h"
10#include "ash/wm/workspace/phantom_window_controller.h"
11#include "ui/aura/window.h"
12#include "ui/wm/core/coordinate_conversion.h"
13
14namespace ash {
15
Evan Stadeeb42d772019-05-03 01:51:3416SnapControllerImpl::SnapControllerImpl() = default;
17SnapControllerImpl::~SnapControllerImpl() = default;
Evan Stade1b050fed2018-09-21 21:17:1718
Evan Stadeeb42d772019-05-03 01:51:3419bool SnapControllerImpl::CanSnap(aura::Window* window) {
Evan Stade1b050fed2018-09-21 21:17:1720 return wm::GetWindowState(window)->CanSnap();
21}
22
Evan Stadeeb42d772019-05-03 01:51:3423void SnapControllerImpl::ShowSnapPreview(aura::Window* window,
24 SnapDirection snap) {
25 if (snap == SnapDirection::kNone) {
Evan Stade1b050fed2018-09-21 21:17:1726 phantom_window_controller_.reset();
27 return;
28 }
29
30 if (!phantom_window_controller_ ||
31 phantom_window_controller_->window() != window) {
32 phantom_window_controller_ =
33 std::make_unique<PhantomWindowController>(window);
34 }
35 gfx::Rect phantom_bounds_in_screen =
Evan Stadeeb42d772019-05-03 01:51:3436 (snap == SnapDirection::kLeft)
Evan Stade1b050fed2018-09-21 21:17:1737 ? wm::GetDefaultLeftSnappedWindowBoundsInParent(window)
38 : wm::GetDefaultRightSnappedWindowBoundsInParent(window);
39 ::wm::ConvertRectToScreen(window->parent(), &phantom_bounds_in_screen);
40 phantom_window_controller_->Show(phantom_bounds_in_screen);
41}
42
Evan Stadeeb42d772019-05-03 01:51:3443void SnapControllerImpl::CommitSnap(aura::Window* window, SnapDirection snap) {
Evan Stade1b050fed2018-09-21 21:17:1744 phantom_window_controller_.reset();
Evan Stadeeb42d772019-05-03 01:51:3445 if (snap == SnapDirection::kNone)
Evan Stade1b050fed2018-09-21 21:17:1746 return;
47
48 wm::WindowState* window_state = wm::GetWindowState(window);
Evan Stadeeb42d772019-05-03 01:51:3449 const wm::WMEvent snap_event(snap == SnapDirection::kLeft
Evan Stade4b099f92018-09-27 16:30:1950 ? wm::WM_EVENT_SNAP_LEFT
51 : wm::WM_EVENT_SNAP_RIGHT);
Evan Stade1b050fed2018-09-21 21:17:1752 window_state->OnWMEvent(&snap_event);
53}
54
55} // namespace ash