diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-21 19:47:39 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-21 19:47:39 +0000 |
commit | adc93fa7b94a6ae044a3fd94ec613cf672b6b7a3 (patch) | |
tree | 82b4d54c1dd24d03c62146939437d580d2c7e68e /views/widget | |
parent | f1dbc2b87c692d0d90a221d2672d51d909cb5d9a (diff) | |
download | chromium_src-adc93fa7b94a6ae044a3fd94ec613cf672b6b7a3.zip chromium_src-adc93fa7b94a6ae044a3fd94ec613cf672b6b7a3.tar.gz chromium_src-adc93fa7b94a6ae044a3fd94ec613cf672b6b7a3.tar.bz2 |
Adds Layer as a class between View and the Texture.
BUG=none
TEST=none
R=ben@chromium.org,wjmaclean@chromium.org
Review URL: http://codereview.chromium.org/7189067
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89880 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r-- | views/widget/native_widget_views.cc | 40 | ||||
-rw-r--r-- | views/widget/native_widget_views.h | 4 | ||||
-rw-r--r-- | views/widget/root_view.cc | 6 | ||||
-rw-r--r-- | views/widget/root_view.h | 1 | ||||
-rw-r--r-- | views/widget/widget.cc | 12 | ||||
-rw-r--r-- | views/widget/widget.h | 9 |
6 files changed, 58 insertions, 14 deletions
diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc index dede2f5..6c3f43c 100644 --- a/views/widget/native_widget_views.cc +++ b/views/widget/native_widget_views.cc @@ -4,6 +4,8 @@ #include "views/widget/native_widget_views.h" +#include "ui/gfx/compositor/compositor.h" +#include "ui/gfx/transform.h" #include "views/view.h" #include "views/views_delegate.h" #include "views/widget/native_widget_view.h" @@ -17,6 +19,7 @@ NativeWidgetViews::NativeWidgetViews(internal::NativeWidgetDelegate* delegate) : delegate_(delegate), view_(NULL), active_(false), + minimized_(false), ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)) { } @@ -41,7 +44,7 @@ void NativeWidgetViews::OnActivate(bool active) { void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) { view_ = new internal::NativeWidgetView(this); - view_->SetPaintToTexture(true); + view_->SetPaintToLayer(true); View* desktop_view = ViewsDelegate::views_delegate->GetDefaultParentView(); desktop_view->AddChildView(view_); @@ -263,7 +266,33 @@ void NativeWidgetViews::Maximize() { } void NativeWidgetViews::Minimize() { - NOTIMPLEMENTED(); + gfx::Rect view_bounds = view_->bounds(); + gfx::Rect parent_bounds = view_->parent()->bounds(); + + restored_bounds_ = view_bounds; + + float aspect_ratio = static_cast<float>(view_bounds.width()) / + static_cast<float>(view_bounds.height()); + int target_size = 100; + int target_height = target_size; + int target_width = static_cast<int>(aspect_ratio * target_height); + if (target_width > target_size) { + target_width = target_size; + target_height = static_cast<int>(target_width / aspect_ratio); + } + + int target_x = 20; + int target_y = parent_bounds.height() - target_size - 20; + + view_->SetBounds( + target_x, target_y, view_bounds.width(), view_bounds.height()); + + ui::Transform transform; + transform.SetScale((float)target_width / (float)view_bounds.width(), + (float)target_height / (float)view_bounds.height()); + view_->SetTransform(transform); + + minimized_ = true; } bool NativeWidgetViews::IsMaximized() const { @@ -272,12 +301,13 @@ bool NativeWidgetViews::IsMaximized() const { } bool NativeWidgetViews::IsMinimized() const { - NOTIMPLEMENTED(); - return false; + return minimized_; } void NativeWidgetViews::Restore() { - NOTIMPLEMENTED(); + minimized_ = false; + view_->SetBoundsRect(restored_bounds_); + view_->SetTransform(ui::Transform()); } void NativeWidgetViews::SetFullscreen(bool fullscreen) { diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h index 533a96a..d5ddeb2 100644 --- a/views/widget/native_widget_views.h +++ b/views/widget/native_widget_views.h @@ -116,10 +116,14 @@ class NativeWidgetViews : public internal::NativeWidgetPrivate { bool active_; + bool minimized_; + // The following factory is used for calls to close the NativeWidgetViews // instance. ScopedRunnableMethodFactory<NativeWidgetViews> close_widget_factory_; + gfx::Rect restored_bounds_; + DISALLOW_COPY_AND_ASSIGN(NativeWidgetViews); }; diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc index 5002281..b50fbba 100644 --- a/views/widget/root_view.cc +++ b/views/widget/root_view.cc @@ -156,7 +156,7 @@ std::string RootView::GetClassName() const { } void RootView::SchedulePaintInRect(const gfx::Rect& rect) { - MarkTextureDirty(); + MarkLayerDirty(); SchedulePaintInternal(rect); } @@ -427,10 +427,6 @@ void RootView::OnPaint(gfx::Canvas* canvas) { canvas->AsCanvasSkia()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); } -bool RootView::ShouldPaintToTexture() const { - return widget_->compositor() != NULL; -} - const ui::Compositor* RootView::GetCompositor() const { return widget_->compositor(); } diff --git a/views/widget/root_view.h b/views/widget/root_view.h index efc889d..7ab3755 100644 --- a/views/widget/root_view.h +++ b/views/widget/root_view.h @@ -127,7 +127,6 @@ class RootView : public View, virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child) OVERRIDE; virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; - virtual bool ShouldPaintToTexture() const OVERRIDE; virtual const ui::Compositor* GetCompositor() const OVERRIDE; virtual ui::Compositor* GetCompositor() OVERRIDE; diff --git a/views/widget/widget.cc b/views/widget/widget.cc index 85aabe4..c633158 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -768,7 +768,7 @@ bool Widget::OnNativeWidgetPaintAccelerated(const gfx::Rect& dirty_region) { return false; compositor_->NotifyStart(); - GetRootView()->PaintToTexture(dirty_region); + GetRootView()->PaintToLayer(dirty_region); GetRootView()->PaintComposite(); compositor_->NotifyEnd(); return true; @@ -909,6 +909,9 @@ void Widget::ReplaceFocusManager(FocusManager* focus_manager) { //////////////////////////////////////////////////////////////////////////////// // Widget, private: +// static +ui::Compositor*(*Widget::factory_)() = NULL; + void Widget::EnsureCompositor() { DCHECK(!compositor_.get()); @@ -916,8 +919,11 @@ void Widget::EnsureCompositor() { // instead of creating a new one here. gfx::AcceleratedWidget widget = native_widget_->GetAcceleratedWidget(); if (widget != gfx::kNullAcceleratedWidget && - View::get_use_acceleration_when_possible()) - compositor_ = ui::Compositor::Create(widget); + View::get_use_acceleration_when_possible()) { + compositor_ = factory_ ? (*factory_)() : ui::Compositor::Create(widget); + if (compositor_.get()) + GetRootView()->SetPaintToLayer(true); + } } bool Widget::ShouldReleaseCaptureOnMouseReleased() const { diff --git a/views/widget/widget.h b/views/widget/widget.h index 9af8da2..463f547 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -464,6 +464,12 @@ class Widget : public internal::NativeWidgetDelegate, return non_client_view()->client_view(); } +#if defined(UNIT_TEST) + static void set_compositor_factory(ui::Compositor*(*factory)()) { + factory_ = factory; + } +#endif + const ui::Compositor* compositor() const { return compositor_.get(); } ui::Compositor* compositor() { return compositor_.get(); } @@ -636,6 +642,9 @@ class Widget : public internal::NativeWidgetDelegate, // The smallest size the window can be. gfx::Size minimum_size_; + // Factory used to create Compositors. Settable by tests. + static ui::Compositor*(*factory_)(); + DISALLOW_COPY_AND_ASSIGN(Widget); }; |