Commit 0b227727 authored by ben's avatar ben Committed by Commit bot

Adds sizing, maximizing, minimizing to simple_wm

R=jcivelli@chromium.org

Review-Url: https://codereview.chromium.org/2587183002
Cr-Commit-Position: refs/heads/master@{#439880}
parent 2ce98a25
...@@ -6,8 +6,10 @@ ...@@ -6,8 +6,10 @@
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/base/ui_base_types.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/gfx/geometry/point_conversions.h" #include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -159,6 +161,21 @@ bool MoveLoop::DetermineType(int ht_location, ...@@ -159,6 +161,21 @@ bool MoveLoop::DetermineType(int ht_location,
} }
void MoveLoop::MoveImpl(const ui::PointerEvent& event) { void MoveLoop::MoveImpl(const ui::PointerEvent& event) {
ui::WindowShowState show_state =
target_->GetProperty(aura::client::kShowStateKey);
// TODO(beng): figure out if there might not be another place to put this,
// perhaps prior to move loop creation.
if (show_state == ui::SHOW_STATE_MAXIMIZED) {
base::AutoReset<bool> resetter(&changing_bounds_, true);
target_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
gfx::Rect restored_bounds =
*target_->GetProperty(aura::client::kRestoreBoundsKey);
// TODO(beng): Not just enough to adjust width and height, probably also
// need to take some action to recenter the window relative to
// the pointer position within the titlebar.
initial_window_bounds_.set_width(restored_bounds.width());
initial_window_bounds_.set_height(restored_bounds.height());
}
const gfx::Vector2d delta = const gfx::Vector2d delta =
event.root_location() - initial_event_screen_location_; event.root_location() - initial_event_screen_location_;
const gfx::Rect new_bounds(DetermineBoundsFromDelta(delta)); const gfx::Rect new_bounds(DetermineBoundsFromDelta(delta));
......
...@@ -108,7 +108,7 @@ class MoveLoop : public aura::WindowObserver { ...@@ -108,7 +108,7 @@ class MoveLoop : public aura::WindowObserver {
const gfx::Point initial_event_screen_location_; const gfx::Point initial_event_screen_location_;
// Original bounds of the window. // Original bounds of the window.
const gfx::Rect initial_window_bounds_; gfx::Rect initial_window_bounds_;
const gfx::Rect initial_user_set_bounds_; const gfx::Rect initial_user_set_bounds_;
// Set to true when MoveLoop changes the bounds of |target_|. The move is // Set to true when MoveLoop changes the bounds of |target_|. The move is
......
...@@ -27,6 +27,7 @@ namespace { ...@@ -27,6 +27,7 @@ namespace {
const int kNonClientTopHeight = 24; const int kNonClientTopHeight = 24;
const int kNonClientSize = 5; const int kNonClientSize = 5;
const int kNonClientMaximizedTopOverlap = 4;
} // namespace } // namespace
...@@ -133,6 +134,9 @@ class SimpleWM::WindowListView : public views::WidgetDelegateView, ...@@ -133,6 +134,9 @@ class SimpleWM::WindowListView : public views::WidgetDelegateView,
} }
void OnPaint(gfx::Canvas* canvas) override { void OnPaint(gfx::Canvas* canvas) override {
canvas->DrawColor(SK_ColorLTGRAY); canvas->DrawColor(SK_ColorLTGRAY);
gfx::Rect stroke_bounds = GetLocalBounds();
stroke_bounds.set_height(1);
canvas->FillRect(stroke_bounds, SK_ColorDKGRAY);
} }
gfx::Size GetPreferredSize() const override { gfx::Size GetPreferredSize() const override {
std::unique_ptr<views::MdTextButton> measure_button( std::unique_ptr<views::MdTextButton> measure_button(
...@@ -212,14 +216,36 @@ class SimpleWM::FrameView : public views::WidgetDelegateView, ...@@ -212,14 +216,36 @@ class SimpleWM::FrameView : public views::WidgetDelegateView,
// Client offsets are applied automatically by the window service. // Client offsets are applied automatically by the window service.
gfx::Rect parent_bounds = GetWidget()->GetNativeWindow()->bounds(); gfx::Rect parent_bounds = GetWidget()->GetNativeWindow()->bounds();
parent_bounds.set_origin(gfx::Point()); parent_bounds.set_origin(gfx::Point());
if (GetWidget()->IsMaximized()) {
parent_bounds.Inset(-kNonClientSize, -kNonClientMaximizedTopOverlap,
-kNonClientSize, -kNonClientSize);
}
client_window_->SetBounds(parent_bounds); client_window_->SetBounds(parent_bounds);
} }
bool CanMaximize() const override {
return (client_window_->GetProperty(aura::client::kResizeBehaviorKey) &
ui::mojom::kResizeBehaviorCanMaximize) != 0;
}
bool CanMinimize() const override {
return (client_window_->GetProperty(aura::client::kResizeBehaviorKey) &
ui::mojom::kResizeBehaviorCanMinimize) != 0;
}
bool CanResize() const override {
return (client_window_->GetProperty(aura::client::kResizeBehaviorKey) &
ui::mojom::kResizeBehaviorCanResize) != 0;
}
// aura::WindowObserver: // aura::WindowObserver:
void OnWindowPropertyChanged(aura::Window* window, const void* key, void OnWindowPropertyChanged(aura::Window* window, const void* key,
intptr_t old) override { intptr_t old) override {
if (key == aura::client::kTitleKey) if (key == aura::client::kTitleKey)
GetWidget()->UpdateWindowTitle(); GetWidget()->UpdateWindowTitle();
else if (key == aura::client::kResizeBehaviorKey)
GetWidget()->non_client_view()->frame_view()->Layout();
} }
aura::Window* client_window_; aura::Window* client_window_;
...@@ -228,6 +254,49 @@ class SimpleWM::FrameView : public views::WidgetDelegateView, ...@@ -228,6 +254,49 @@ class SimpleWM::FrameView : public views::WidgetDelegateView,
DISALLOW_COPY_AND_ASSIGN(FrameView); DISALLOW_COPY_AND_ASSIGN(FrameView);
}; };
class SimpleWM::WorkspaceLayoutManager : public aura::WindowObserver {
public:
explicit WorkspaceLayoutManager(aura::Window* window_root)
: window_root_(window_root) {}
~WorkspaceLayoutManager() override {}
private:
// aura::WindowObserver:
void OnWindowPropertyChanged(aura::Window* window, const void* key,
intptr_t old) override {
if (key == aura::client::kShowStateKey) {
ui::WindowShowState show_state =
window->GetProperty(aura::client::kShowStateKey);
switch (show_state) {
case ui::SHOW_STATE_NORMAL:
window->Show();
window->SetBounds(
*window->GetProperty(aura::client::kRestoreBoundsKey));
break;
case ui::SHOW_STATE_MINIMIZED:
window->Hide();
break;
case ui::SHOW_STATE_MAXIMIZED:
window->Show();
window->SetProperty(aura::client::kRestoreBoundsKey,
new gfx::Rect(window->bounds()));
window->SetBounds(gfx::Rect(window_root_->bounds().size()));
break;
default:
NOTREACHED();
break;
}
}
}
void OnWindowDestroying(aura::Window* window) override {
window->RemoveObserver(this);
}
aura::Window* window_root_;
DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManager);
};
class SimpleWM::DisplayLayoutManager : public aura::LayoutManager { class SimpleWM::DisplayLayoutManager : public aura::LayoutManager {
public: public:
DisplayLayoutManager(aura::Window* display_root, DisplayLayoutManager(aura::Window* display_root,
...@@ -381,6 +450,7 @@ aura::Window* SimpleWM::OnWmCreateTopLevelWindow( ...@@ -381,6 +450,7 @@ aura::Window* SimpleWM::OnWmCreateTopLevelWindow(
frame_view->Init(); frame_view->Init();
frame_widget->GetNativeWindow()->AddChild(client_window); frame_widget->GetNativeWindow()->AddChild(client_window);
frame_widget->GetNativeWindow()->AddObserver(workspace_layout_manager_.get());
client_window_to_frame_view_[client_window] = frame_view; client_window_to_frame_view_[client_window] = frame_view;
// TODO(beng): probably need to observe client_window from now on so we can // TODO(beng): probably need to observe client_window from now on so we can
...@@ -410,9 +480,12 @@ void SimpleWM::OnWmNewDisplay( ...@@ -410,9 +480,12 @@ void SimpleWM::OnWmNewDisplay(
window_tree_host_->window()->Show(); window_tree_host_->window()->Show();
display_root_ = window_tree_host_->window(); display_root_ = window_tree_host_->window();
window_root_ = new aura::Window(nullptr); window_root_ = new aura::Window(nullptr);
window_root_->Init(ui::LAYER_NOT_DRAWN); window_root_->Init(ui::LAYER_SOLID_COLOR);
window_root_->layer()->SetColor(SK_ColorWHITE);
display_root_->AddChild(window_root_); display_root_->AddChild(window_root_);
window_root_->Show(); window_root_->Show();
workspace_layout_manager_ =
base::MakeUnique<WorkspaceLayoutManager>(window_root_);
window_list_model_ = base::MakeUnique<WindowListModel>(window_root_); window_list_model_ = base::MakeUnique<WindowListModel>(window_root_);
...@@ -477,6 +550,7 @@ SimpleWM::FrameView* SimpleWM::GetFrameViewForClientWindow( ...@@ -477,6 +550,7 @@ SimpleWM::FrameView* SimpleWM::GetFrameViewForClientWindow(
} }
void SimpleWM::OnWindowListViewItemActivated(aura::Window* window) { void SimpleWM::OnWindowListViewItemActivated(aura::Window* window) {
window->Show();
aura::client::ActivationClient* activation_client = aura::client::ActivationClient* activation_client =
aura::client::GetActivationClient(window->GetRootWindow()); aura::client::GetActivationClient(window->GetRootWindow());
activation_client->ActivateWindow(window); activation_client->ActivateWindow(window);
......
...@@ -52,6 +52,7 @@ class SimpleWM : public service_manager::Service, ...@@ -52,6 +52,7 @@ class SimpleWM : public service_manager::Service,
class WindowListModel; class WindowListModel;
class WindowListModelObserver; class WindowListModelObserver;
class WindowListView; class WindowListView;
class WorkspaceLayoutManager;
// service_manager::Service: // service_manager::Service:
void OnStart() override; void OnStart() override;
...@@ -113,6 +114,7 @@ class SimpleWM : public service_manager::Service, ...@@ -113,6 +114,7 @@ class SimpleWM : public service_manager::Service,
std::unique_ptr<aura::MusContextFactory> compositor_context_factory_; std::unique_ptr<aura::MusContextFactory> compositor_context_factory_;
std::map<aura::Window*, FrameView*> client_window_to_frame_view_; std::map<aura::Window*, FrameView*> client_window_to_frame_view_;
std::unique_ptr<WindowListModel> window_list_model_; std::unique_ptr<WindowListModel> window_list_model_;
std::unique_ptr<WorkspaceLayoutManager> workspace_layout_manager_;
bool started_ = false; bool started_ = false;
......
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