Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: ui/aura/window_unittest.cc

Issue 102313002: Wires up painting of layerless children (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/window.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/window.h" 5 #include "ui/aura/window.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 23 matching lines...) Expand all
34 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 34 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
35 #include "ui/compositor/scoped_layer_animation_settings.h" 35 #include "ui/compositor/scoped_layer_animation_settings.h"
36 #include "ui/compositor/test/test_layers.h" 36 #include "ui/compositor/test/test_layers.h"
37 #include "ui/events/event.h" 37 #include "ui/events/event.h"
38 #include "ui/events/event_utils.h" 38 #include "ui/events/event_utils.h"
39 #include "ui/events/gestures/gesture_configuration.h" 39 #include "ui/events/gestures/gesture_configuration.h"
40 #include "ui/events/keycodes/keyboard_codes.h" 40 #include "ui/events/keycodes/keyboard_codes.h"
41 #include "ui/gfx/canvas.h" 41 #include "ui/gfx/canvas.h"
42 #include "ui/gfx/screen.h" 42 #include "ui/gfx/screen.h"
43 #include "ui/gfx/skia_util.h" 43 #include "ui/gfx/skia_util.h"
44 #include "ui/gfx/vector2d.h"
44 45
45 DECLARE_WINDOW_PROPERTY_TYPE(const char*) 46 DECLARE_WINDOW_PROPERTY_TYPE(const char*)
46 DECLARE_WINDOW_PROPERTY_TYPE(int) 47 DECLARE_WINDOW_PROPERTY_TYPE(int)
47 48
48 namespace aura { 49 namespace aura {
49 namespace test { 50 namespace test {
50 51
51 class WindowTest : public AuraTestBase { 52 class WindowTest : public AuraTestBase {
52 public: 53 public:
53 WindowTest() : max_separation_(0) { 54 WindowTest() : max_separation_(0) {
(...skipping 3305 matching lines...) Expand 10 before | Expand all | Expand 10 after
3359 3360
3360 root.RemoveChild(w1ll); 3361 root.RemoveChild(w1ll);
3361 3362
3362 w111->SetBounds(gfx::Rect(7, 8, 11, 12)); 3363 w111->SetBounds(gfx::Rect(7, 8, 11, 12));
3363 EXPECT_EQ("7,8 11x12", w111->bounds().ToString()); 3364 EXPECT_EQ("7,8 11x12", w111->bounds().ToString());
3364 EXPECT_EQ("7,8 11x12", w111->layer()->bounds().ToString()); 3365 EXPECT_EQ("7,8 11x12", w111->layer()->bounds().ToString());
3365 3366
3366 delete w1ll; 3367 delete w1ll;
3367 } 3368 }
3368 3369
3370 namespace {
3371
3372 // Tracks the number of times paint is invoked along with what the clip and
3373 // translate was.
3374 class PaintWindowDelegate : public TestWindowDelegate {
3375 public:
3376 PaintWindowDelegate() : paint_count_(0) {}
3377 virtual ~PaintWindowDelegate() {}
3378
3379 const gfx::Rect& most_recent_paint_clip_bounds() const {
3380 return most_recent_paint_clip_bounds_;
3381 }
3382
3383 const gfx::Vector2d& most_recent_paint_matrix_offset() const {
3384 return most_recent_paint_matrix_offset_;
3385 }
3386
3387 void clear_paint_count() { paint_count_ = 0; }
3388 int paint_count() const { return paint_count_; }
3389
3390 // TestWindowDelegate::
3391 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
3392 paint_count_++;
3393 canvas->GetClipBounds(&most_recent_paint_clip_bounds_);
3394 const SkMatrix& matrix = canvas->sk_canvas()->getTotalMatrix();
3395 most_recent_paint_matrix_offset_ = gfx::Vector2d(
3396 SkScalarFloorToInt(matrix.getTranslateX()),
3397 SkScalarFloorToInt(matrix.getTranslateY()));
3398 }
3399
3400 private:
3401 int paint_count_;
3402 gfx::Rect most_recent_paint_clip_bounds_;
3403 gfx::Vector2d most_recent_paint_matrix_offset_;
3404
3405 DISALLOW_COPY_AND_ASSIGN(PaintWindowDelegate);
3406 };
3407
3408 } // namespace
3409
3410 // Assertions around layerless children being painted when non-layerless window
3411 // is painted.
3412 TEST_F(WindowTest, PaintLayerless) {
3413 // Creates the following structure (all children owned by root):
3414 // root
3415 // w1ll 1,2 40x50
3416 // w11ll 3,4 11x12
3417 // w111 5,6
3418 //
3419 // ll: layer less, eg no layer
3420 PaintWindowDelegate w1ll_delegate;
3421 PaintWindowDelegate w11ll_delegate;
3422 PaintWindowDelegate w111_delegate;
3423
3424 Window root(NULL);
3425 root.InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN);
3426 root.SetBounds(gfx::Rect(0, 0, 100, 100));
3427
3428 Window* w1ll = new Window(&w1ll_delegate);
3429 w1ll->InitWithWindowLayerType(WINDOW_LAYER_NONE);
3430 w1ll->SetBounds(gfx::Rect(1, 2, 40, 50));
3431 w1ll->Show();
3432 root.AddChild(w1ll);
3433
3434 Window* w11ll = new Window(&w11ll_delegate);
3435 w11ll->InitWithWindowLayerType(WINDOW_LAYER_NONE);
3436 w11ll->SetBounds(gfx::Rect(3, 4, 11, 12));
3437 w11ll->Show();
3438 w1ll->AddChild(w11ll);
3439
3440 Window* w111 = new Window(&w111_delegate);
3441 w111->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN);
3442 w111->SetBounds(gfx::Rect(5, 6, 100, 100));
3443 w111->Show();
3444 w11ll->AddChild(w111);
3445
3446 EXPECT_EQ(0, w1ll_delegate.paint_count());
3447 EXPECT_EQ(0, w11ll_delegate.paint_count());
3448 EXPECT_EQ(0, w111_delegate.paint_count());
3449
3450 // Paint the root, this should trigger painting of the two layerless
3451 // descendants but not the layered descendant.
3452 gfx::Canvas canvas(gfx::Size(200, 200), 1.0f, true);
3453 static_cast<ui::LayerDelegate&>(root).OnPaintLayer(&canvas);
3454
3455 // NOTE: SkCanvas::getClipBounds() extends the clip 1 pixel to the left and up
3456 // and 2 pixels down and to the right.
3457 EXPECT_EQ(1, w1ll_delegate.paint_count());
3458 EXPECT_EQ("-1,-1 42x52",
3459 w1ll_delegate.most_recent_paint_clip_bounds().ToString());
3460 EXPECT_EQ("[1 2]",
3461 w1ll_delegate.most_recent_paint_matrix_offset().ToString());
3462 EXPECT_EQ(1, w11ll_delegate.paint_count());
3463 EXPECT_EQ("-1,-1 13x14",
3464 w11ll_delegate.most_recent_paint_clip_bounds().ToString());
3465 EXPECT_EQ("[4 6]",
3466 w11ll_delegate.most_recent_paint_matrix_offset().ToString());
3467 EXPECT_EQ(0, w111_delegate.paint_count());
3468 }
3469
3369 } // namespace test 3470 } // namespace test
3370 } // namespace aura 3471 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698