diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-27 23:33:48 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-27 23:33:48 +0000 |
commit | 3f6ffb8f5a4a78d63a53526c220e74a500fa8eba (patch) | |
tree | d07b13f007134878d268db46087f80c19dd8c088 /ash/wm | |
parent | 084d97a144cba94376a578190839aa96ddb7d78c (diff) | |
download | chromium_src-3f6ffb8f5a4a78d63a53526c220e74a500fa8eba.zip chromium_src-3f6ffb8f5a4a78d63a53526c220e74a500fa8eba.tar.gz chromium_src-3f6ffb8f5a4a78d63a53526c220e74a500fa8eba.tar.bz2 |
This change makes Aura/Views to use DIP, while keeping layer to use Pixels. This allow chrome/ash to run on high density screen in High Density Incompatible mode (everything scaled to 2x), except for web contents.
I put this behind ENABLE_DIP to avoid regression. I'll make it runtime flag next week when we get render working.
BUG=114666
TEST=manual: run with --aura-host-window-size=1000x800*2.
Review URL: https://chromiumcodereview.appspot.com/10081011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134391 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/wm')
-rw-r--r-- | ash/wm/image_grid.cc | 38 | ||||
-rw-r--r-- | ash/wm/image_grid.h | 15 | ||||
-rw-r--r-- | ash/wm/image_grid_unittest.cc | 12 | ||||
-rw-r--r-- | ash/wm/resize_shadow.cc | 2 | ||||
-rw-r--r-- | ash/wm/shadow.cc | 4 | ||||
-rw-r--r-- | ash/wm/shadow.h | 10 | ||||
-rw-r--r-- | ash/wm/shadow_controller.cc | 3 | ||||
-rw-r--r-- | ash/wm/shelf_layout_manager.cc | 10 | ||||
-rw-r--r-- | ash/wm/window_animations.cc | 29 |
9 files changed, 84 insertions, 39 deletions
diff --git a/ash/wm/image_grid.cc b/ash/wm/image_grid.cc index 99fb8ff..2edb3f5 100644 --- a/ash/wm/image_grid.cc +++ b/ash/wm/image_grid.cc @@ -6,8 +6,10 @@ #include <algorithm> +#include "ui/aura/dip_util.h" #include "ui/gfx/canvas.h" #include "ui/gfx/image/image.h" +#include "ui/gfx/rect.h" #include "ui/gfx/transform.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkXfermode.h" @@ -25,8 +27,9 @@ gfx::Rect ImageGrid::TestAPI::GetTransformedLayerBounds( return bounds; } -ImageGrid::ImageGrid() - : layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), +ImageGrid::ImageGrid(aura::Window* window) + : window_(window), + layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), top_image_height_(0), bottom_image_height_(0), left_image_width_(0), @@ -203,16 +206,21 @@ void ImageGrid::SetSize(const gfx::Size& size) { } } -void ImageGrid::SetContentBounds(const gfx::Rect& content_bounds) { - SetSize( - gfx::Size( - content_bounds.width() + left_image_width_ + right_image_width_, - content_bounds.height() + top_image_height_ + bottom_image_height_)); - layer_->SetBounds( - gfx::Rect(content_bounds.x() - left_image_width_, - content_bounds.y() - top_image_height_, - layer_->bounds().width(), - layer_->bounds().height())); +void ImageGrid::SetContentBounds(const gfx::Rect& content_bounds_in_dip) { +#if defined(ENABLE_DIP) + // TODO(oshma): Scale the size of the shadow. + const gfx::Rect content_bounds = + aura::ConvertRectToPixel(window_, content_bounds_in_dip); +#else + const gfx::Rect& content_bounds = content_bounds_in_dip; +#endif + SetSize(gfx::Size( + content_bounds.width() + left_image_width_ + right_image_width_, + content_bounds.height() + top_image_height_ + bottom_image_height_)); + layer_->SetBounds(gfx::Rect(content_bounds.x() - left_image_width_, + content_bounds.y() - top_image_height_, + layer_->bounds().width(), + layer_->bounds().height())); } void ImageGrid::ImagePainter::SetClipRect(const gfx::Rect& clip_rect, @@ -259,7 +267,13 @@ void ImageGrid::SetImage(const gfx::Image* image, // Set up the new layer and painter. layer_ptr->reset(new ui::Layer(ui::LAYER_TEXTURED)); +#if defined(ENABLE_DIP) + const gfx::Size size = + aura::ConvertSizeToPixel(window_, GetImageSize(image)); +#else const gfx::Size size = GetImageSize(image); +#endif + layer_ptr->get()->SetBounds(gfx::Rect(0, 0, size.width(), size.height())); painter_ptr->reset(new ImagePainter(image)); diff --git a/ash/wm/image_grid.h b/ash/wm/image_grid.h index 5794a74..84119f5 100644 --- a/ash/wm/image_grid.h +++ b/ash/wm/image_grid.h @@ -15,6 +15,10 @@ #include "ui/gfx/rect.h" #include "ui/gfx/size.h" +namespace aura { +class Window; +} // namespace aura + namespace gfx { class Image; } // namespace gfx @@ -87,7 +91,7 @@ class ASH_EXPORT ImageGrid { DISALLOW_COPY_AND_ASSIGN(TestAPI); }; - ImageGrid(); + explicit ImageGrid(aura::Window* window); ~ImageGrid(); ui::Layer* layer() { return layer_.get(); } @@ -123,8 +127,8 @@ class ASH_EXPORT ImageGrid { void SetSize(const gfx::Size& size); // Sets the grid to a position and size such that the inner edges of the top, - // bottom, left and right images will be flush with |content_bounds|. - void SetContentBounds(const gfx::Rect& content_bounds); + // bottom, left and right images will be flush with |content_bounds_in_dip|. + void SetContentBounds(const gfx::Rect& content_bounds_in_dip); private: // Delegate responsible for painting a specific image on a layer. @@ -163,6 +167,11 @@ class ASH_EXPORT ImageGrid { scoped_ptr<ui::Layer>* layer_ptr, scoped_ptr<ImagePainter>* painter_ptr); + // A possibly-arbitrary window that is drawn at the same DPI + // (i.e. on the same monitor) as this grid. + // TODO(oshima): move scale factor to gfx/compositor and remove this. + aura::Window* window_; + // Layer that contains all of the image layers. scoped_ptr<ui::Layer> layer_; diff --git a/ash/wm/image_grid_unittest.cc b/ash/wm/image_grid_unittest.cc index 715ddb9..bb31c31 100644 --- a/ash/wm/image_grid_unittest.cc +++ b/ash/wm/image_grid_unittest.cc @@ -37,7 +37,7 @@ TEST_F(ImageGridTest, Basic) { scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1))); scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder))); - ImageGrid grid; + ImageGrid grid(NULL); grid.SetImages(image_BxB.get(), image_1xB.get(), image_BxB.get(), image_Bx1.get(), image_1x1.get(), image_Bx1.get(), image_BxB.get(), image_1xB.get(), image_BxB.get()); @@ -129,7 +129,7 @@ TEST_F(ImageGridTest, SetContentBounds) { scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1))); scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder))); - ImageGrid grid; + ImageGrid grid(NULL); grid.SetImages(image_BxB.get(), image_1xB.get(), image_BxB.get(), image_Bx1.get(), image_1x1.get(), image_Bx1.get(), image_BxB.get(), image_1xB.get(), image_BxB.get()); @@ -154,7 +154,7 @@ TEST_F(ImageGridTest, SingleImage) { const int kBorder = 1; scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); - ImageGrid grid; + ImageGrid grid(NULL); grid.SetImages(NULL, image.get(), NULL, NULL, NULL, NULL, NULL, NULL, NULL); @@ -186,7 +186,7 @@ TEST_F(ImageGridTest, ResetImages) { const int kBorder = 1; scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); - ImageGrid grid; + ImageGrid grid(NULL); grid.SetImages(NULL, image.get(), NULL, NULL, NULL, NULL, NULL, NULL, NULL); @@ -234,7 +234,7 @@ TEST_F(ImageGridTest, SmallerSides) { scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); - ImageGrid grid; + ImageGrid grid(NULL); grid.SetImages(top_left_image.get(), top_image.get(), top_right_image.get(), left_image.get(), NULL, right_image.get(), NULL, NULL, NULL); @@ -287,7 +287,7 @@ TEST_F(ImageGridTest, TooSmall) { scoped_ptr<gfx::Image> bottom_right_image( CreateImage(gfx::Size(kCorner, kCorner))); - ImageGrid grid; + ImageGrid grid(NULL); grid.SetImages( top_left_image.get(), top_image.get(), top_right_image.get(), left_image.get(), center_image.get(), right_image.get(), diff --git a/ash/wm/resize_shadow.cc b/ash/wm/resize_shadow.cc index 5807700..f8da30a 100644 --- a/ash/wm/resize_shadow.cc +++ b/ash/wm/resize_shadow.cc @@ -49,7 +49,7 @@ ResizeShadow::~ResizeShadow() {} void ResizeShadow::Init(aura::Window* window) { // Set up our image grid and images. ResourceBundle& res = ResourceBundle::GetSharedInstance(); - image_grid_.reset(new ImageGrid()); + image_grid_.reset(new ImageGrid(window)); image_grid_->SetImages( &res.GetImageNamed(IDR_AURA_RESIZE_SHADOW_TOP_LEFT), &res.GetImageNamed(IDR_AURA_RESIZE_SHADOW_TOP), diff --git a/ash/wm/shadow.cc b/ash/wm/shadow.cc index d763bc7..9cf54c9 100644 --- a/ash/wm/shadow.cc +++ b/ash/wm/shadow.cc @@ -44,9 +44,9 @@ Shadow::Shadow() : style_(STYLE_ACTIVE) { Shadow::~Shadow() { } -void Shadow::Init(Style style) { +void Shadow::Init(aura::Window* window, Style style) { style_ = style; - image_grid_.reset(new ImageGrid); + image_grid_.reset(new ImageGrid(window)); UpdateImagesForStyle(); image_grid_->layer()->set_name("Shadow"); image_grid_->layer()->SetOpacity(GetOpacityForStyle(style_)); diff --git a/ash/wm/shadow.h b/ash/wm/shadow.h index 8f5ab07..ae00a4d 100644 --- a/ash/wm/shadow.h +++ b/ash/wm/shadow.h @@ -12,6 +12,10 @@ #include "ui/gfx/compositor/layer_animation_observer.h" #include "ui/gfx/rect.h" +namespace aura { +class Window; +} // namespace aura + namespace ui { class Layer; } // namespace ui @@ -40,7 +44,11 @@ class ASH_EXPORT Shadow : public ui::ImplicitAnimationObserver { Shadow(); virtual ~Shadow(); - void Init(Style style); + // |window| is a possibly-arbitrary window that is drawn at the same DPI + // (i.e. on the same monitor) as this shadow. The actual bounds for the + // shadow still has to be provided through |SetContentBounds()|. + // TODO(oshima): move scale factor to gfx/compositor and remove this. + void Init(aura::Window* window, Style style); // Returns |image_grid_|'s ui::Layer. This is exposed so it can be added to // the same layer as the content and stacked below it. SetContentBounds() diff --git a/ash/wm/shadow_controller.cc b/ash/wm/shadow_controller.cc index 172300c..869a0b2 100644 --- a/ash/wm/shadow_controller.cc +++ b/ash/wm/shadow_controller.cc @@ -162,7 +162,8 @@ void ShadowController::CreateShadowForWindow(aura::Window* window) { linked_ptr<Shadow> shadow(new Shadow()); window_shadows_.insert(make_pair(window, shadow)); - shadow->Init(ShouldUseSmallShadowForWindow(window) ? + shadow->Init(window, + ShouldUseSmallShadowForWindow(window) ? Shadow::STYLE_SMALL : Shadow::STYLE_ACTIVE); shadow->SetContentBounds(gfx::Rect(window->bounds().size())); shadow->layer()->SetVisible(ShouldShowShadowForWindow(window)); diff --git a/ash/wm/shelf_layout_manager.cc b/ash/wm/shelf_layout_manager.cc index a118893..af5aa75 100644 --- a/ash/wm/shelf_layout_manager.cc +++ b/ash/wm/shelf_layout_manager.cc @@ -14,6 +14,7 @@ #include "base/auto_reset.h" #include "base/i18n/rtl.h" #include "ui/aura/client/activation_client.h" +#include "ui/aura/dip_util.h" #include "ui/aura/event.h" #include "ui/aura/event_filter.h" #include "ui/aura/root_window.h" @@ -36,6 +37,11 @@ ui::Layer* GetLayer(views::Widget* widget) { return widget->GetNativeView()->layer(); } +void SetLayerBounds(views::Widget* widget, const gfx::Rect& bounds) { + aura::Window* window = widget->GetNativeView(); + window->layer()->SetBounds(aura::ConvertRectToPixel(window, bounds)); +} + } // namespace // static @@ -328,7 +334,7 @@ void ShelfLayoutManager::SetState(VisibilityState visibility_state) { launcher_animation_setter.SetTransitionDuration( base::TimeDelta::FromMilliseconds(130)); launcher_animation_setter.SetTweenType(ui::Tween::EASE_OUT); - GetLayer(launcher_widget())->SetBounds(target_bounds.launcher_bounds); + SetLayerBounds(launcher_widget(), target_bounds.launcher_bounds); GetLayer(launcher_widget())->SetOpacity(target_bounds.opacity); } ui::ScopedLayerAnimationSettings status_animation_setter( @@ -336,7 +342,7 @@ void ShelfLayoutManager::SetState(VisibilityState visibility_state) { status_animation_setter.SetTransitionDuration( base::TimeDelta::FromMilliseconds(130)); status_animation_setter.SetTweenType(ui::Tween::EASE_OUT); - GetLayer(status_)->SetBounds(target_bounds.status_bounds); + SetLayerBounds(status_, target_bounds.status_bounds); GetLayer(status_)->SetOpacity(target_bounds.opacity); Shell::GetInstance()->SetMonitorWorkAreaInsets( Shell::GetRootWindow(), diff --git a/ash/wm/window_animations.cc b/ash/wm/window_animations.cc index 168b53d..5839702 100644 --- a/ash/wm/window_animations.cc +++ b/ash/wm/window_animations.cc @@ -14,6 +14,7 @@ #include "base/stl_util.h" #include "base/time.h" #include "ui/aura/client/aura_constants.h" +#include "ui/aura/dip_util.h" #include "ui/aura/window.h" #include "ui/aura/window_observer.h" #include "ui/aura/window_property.h" @@ -230,9 +231,10 @@ void AnimateShowWindow_Drop(aura::Window* window) { ui::Transform transform; transform.ConcatScale(kWindowAnimation_ScaleFactor, kWindowAnimation_ScaleFactor); + gfx::Rect bounds = window->GetBoundsInPixel(); transform.ConcatTranslate( - kWindowAnimation_TranslateFactor * window->bounds().width(), - kWindowAnimation_TranslateFactor * window->bounds().height()); + kWindowAnimation_TranslateFactor * bounds.width(), + kWindowAnimation_TranslateFactor * bounds.height()); AnimateShowWindowCommon(window, transform, ui::Transform()); } @@ -240,9 +242,10 @@ void AnimateHideWindow_Drop(aura::Window* window) { ui::Transform transform; transform.ConcatScale(kWindowAnimation_ScaleFactor, kWindowAnimation_ScaleFactor); + gfx::Rect bounds = window->GetBoundsInPixel(); transform.ConcatTranslate( - kWindowAnimation_TranslateFactor * window->bounds().width(), - kWindowAnimation_TranslateFactor * window->bounds().height()); + kWindowAnimation_TranslateFactor * bounds.width(), + kWindowAnimation_TranslateFactor * bounds.height()); AnimateHideWindowCommon(window, transform); } @@ -273,20 +276,22 @@ void AnimateHideWindow_Fade(aura::Window* window) { ui::Transform BuildWorkspaceSwitchTransform(aura::Window* window) { // Animations for transitioning workspaces scale all windows. To give the // effect of scaling from the center of the screen the windows are translated. - gfx::Rect parent_bounds(window->parent()->bounds()); + gfx::Rect bounds = window->GetBoundsInPixel(); + gfx::Rect parent_bounds(window->parent()->GetBoundsInPixel()); + float mid_x = static_cast<float>(parent_bounds.width()) / 2.0f; float initial_x = - (static_cast<float>(window->bounds().x()) - mid_x) * kWorkspaceScale + + (static_cast<float>(bounds.x()) - mid_x) * kWorkspaceScale + mid_x; float mid_y = static_cast<float>(parent_bounds.height()) / 2.0f; float initial_y = - (static_cast<float>(window->bounds().y()) - mid_y) * kWorkspaceScale + + (static_cast<float>(bounds.y()) - mid_y) * kWorkspaceScale + mid_y; ui::Transform transform; transform.ConcatTranslate( - initial_x - static_cast<float>(window->bounds().x()), - initial_y - static_cast<float>(window->bounds().y())); + initial_x - static_cast<float>(bounds.x()), + initial_y - static_cast<float>(bounds.y())); transform.ConcatScale(kWorkspaceScale, kWorkspaceScale); return transform; } @@ -356,8 +361,10 @@ gfx::Rect GetMinimizeRectForWindow(aura::Window* window) { void AddLayerAnimationsForMinimize(aura::Window* window, bool show) { // Recalculate the transform at restore time since the launcher item may have // moved while the window was minimized. - gfx::Rect bounds = window->bounds(); - gfx::Rect target_bounds = GetMinimizeRectForWindow(window); + gfx::Rect bounds = window->GetBoundsInPixel(); + gfx::Rect target_bounds = + aura::ConvertRectToPixel(window, GetMinimizeRectForWindow(window)); + float scale_x = static_cast<float>(target_bounds.height()) / bounds.width(); float scale_y = static_cast<float>(target_bounds.width()) / bounds.height(); |