summaryrefslogtreecommitdiffstats
path: root/components/exo
diff options
context:
space:
mode:
authorreveman <reveman@chromium.org>2015-11-30 16:46:46 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-01 00:48:09 +0000
commit31a94eb87578d970ead63cb5c8032f95d2c8da92 (patch)
treef22146ab6733f655951c0ae8619d6dc0666f7d6f /components/exo
parent70f2d521f9ffdadad6fcda9e1497e9b0c0c4a62d (diff)
downloadchromium_src-31a94eb87578d970ead63cb5c8032f95d2c8da92.zip
chromium_src-31a94eb87578d970ead63cb5c8032f95d2c8da92.tar.gz
chromium_src-31a94eb87578d970ead63cb5c8032f95d2c8da92.tar.bz2
exo: Refactor ShellSurface class to support popups, resizing, etc.
This changes how widgets are created for shell surfaces. By creating the widget when the surface takes a specific role, hints about size can be communicated to the client to ensure that the initial frame being displayed when the widget is shown is perfect. This is also a prerequisite to interactive window resize. This also allows top-level shell surfaces to be automatically managed by Ash. BUG=549781 TEST=exo_unittests --gtest_filter=ShellSurfaceTest.* Review URL: https://codereview.chromium.org/1484133002 Cr-Commit-Position: refs/heads/master@{#362296}
Diffstat (limited to 'components/exo')
-rw-r--r--components/exo/shell_surface.cc82
-rw-r--r--components/exo/shell_surface.h1
2 files changed, 50 insertions, 33 deletions
diff --git a/components/exo/shell_surface.cc b/components/exo/shell_surface.cc
index 29f6749..dfcc092 100644
--- a/components/exo/shell_surface.cc
+++ b/components/exo/shell_surface.cc
@@ -6,6 +6,7 @@
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
+#include "ash/wm/window_state.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "base/trace_event/trace_event.h"
@@ -44,15 +45,30 @@ class CustomFrameView : public views::NonClientFrameView {
DISALLOW_COPY_AND_ASSIGN(CustomFrameView);
};
+views::Widget::InitParams CreateWidgetInitParams(
+ views::WidgetDelegate* delegate) {
+ views::Widget::InitParams params;
+ params.type = views::Widget::InitParams::TYPE_WINDOW;
+ params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ params.delegate = delegate;
+ params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE;
+ params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
+ params.show_state = ui::SHOW_STATE_NORMAL;
+ params.parent = ash::Shell::GetContainer(
+ ash::Shell::GetPrimaryRootWindow(), ash::kShellWindowId_DefaultContainer);
+ return params;
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
// ShellSurface, public:
-ShellSurface::ShellSurface(Surface* surface)
- : surface_(surface), show_state_(ui::SHOW_STATE_END) {
+ShellSurface::ShellSurface(Surface* surface) : surface_(surface) {
surface_->SetSurfaceDelegate(this);
surface_->AddSurfaceObserver(this);
+ surface_->SetVisible(true);
+ surface_->SetEnabled(true);
}
ShellSurface::~ShellSurface() {
@@ -67,30 +83,50 @@ ShellSurface::~ShellSurface() {
void ShellSurface::SetToplevel() {
TRACE_EVENT0("exo", "ShellSurface::SetToplevel");
- if (!widget_)
- show_state_ = ui::SHOW_STATE_NORMAL;
+ if (widget_) {
+ DLOG(WARNING) << "Shell surface already mapped";
+ return;
+ }
+
+ views::Widget::InitParams params = CreateWidgetInitParams(this);
+ params.bounds = gfx::Rect(gfx::Size(1, 1));
+ widget_.reset(new views::Widget);
+ widget_->Init(params);
+ widget_->GetNativeWindow()->set_owned_by_parent(false);
+
+ // The position of a standard top level shell surface is managed by Ash.
+ ash::wm::GetWindowState(widget_->GetNativeWindow())
+ ->set_window_position_managed(true);
}
void ShellSurface::SetMaximized() {
TRACE_EVENT0("exo", "ShellSurface::SetMaximized");
if (widget_) {
- widget_->Maximize();
+ DLOG(WARNING) << "Shell surface already mapped";
return;
}
- show_state_ = ui::SHOW_STATE_MAXIMIZED;
+ views::Widget::InitParams params = CreateWidgetInitParams(this);
+ params.show_state = ui::SHOW_STATE_MAXIMIZED;
+ widget_.reset(new views::Widget);
+ widget_->Init(params);
+ widget_->GetNativeWindow()->set_owned_by_parent(false);
}
void ShellSurface::SetFullscreen() {
TRACE_EVENT0("exo", "ShellSurface::SetFullscreen");
if (widget_) {
- widget_->SetFullscreen(true);
+ DLOG(WARNING) << "Shell surface already mapped";
return;
}
- show_state_ = ui::SHOW_STATE_FULLSCREEN;
+ views::Widget::InitParams params = CreateWidgetInitParams(this);
+ params.show_state = ui::SHOW_STATE_FULLSCREEN;
+ widget_.reset(new views::Widget);
+ widget_->Init(params);
+ widget_->GetNativeWindow()->set_owned_by_parent(false);
}
void ShellSurface::SetTitle(const base::string16& title) {
@@ -114,32 +150,14 @@ scoped_refptr<base::trace_event::TracedValue> ShellSurface::AsTracedValue()
// SurfaceDelegate overrides:
void ShellSurface::OnSurfaceCommit() {
- if (widget_ || show_state_ == ui::SHOW_STATE_END) {
- surface_->CommitSurfaceHierarchy();
- if (widget_)
- widget_->SetSize(widget_->non_client_view()->GetPreferredSize());
- return;
- }
-
- views::Widget::InitParams params;
- params.type = views::Widget::InitParams::TYPE_WINDOW;
- params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
- params.delegate = this;
- params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE;
- params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
- params.show_state = show_state_;
- params.parent = ash::Shell::GetContainer(
- ash::Shell::GetPrimaryRootWindow(), ash::kShellWindowId_DefaultContainer);
- widget_.reset(new views::Widget);
- widget_->Init(params);
- widget_->GetNativeWindow()->set_owned_by_parent(false);
- widget_->GetNativeView()->SetName("ShellSurface");
-
surface_->CommitSurfaceHierarchy();
- surface_->SetVisible(true);
- surface_->SetEnabled(true);
+ if (widget_) {
+ widget_->SetSize(widget_->non_client_view()->GetPreferredSize());
- widget_->Show();
+ // Show widget if not already visible.
+ if (!widget_->GetNativeWindow()->TargetVisibility())
+ widget_->Show();
+ }
}
bool ShellSurface::IsSurfaceSynchronized() const {
diff --git a/components/exo/shell_surface.h b/components/exo/shell_surface.h
index 6d5950e..4107383 100644
--- a/components/exo/shell_surface.h
+++ b/components/exo/shell_surface.h
@@ -66,7 +66,6 @@ class ShellSurface : public SurfaceDelegate,
private:
scoped_ptr<views::Widget> widget_;
Surface* surface_;
- ui::WindowShowState show_state_;
base::string16 title_;
DISALLOW_COPY_AND_ASSIGN(ShellSurface);