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

Side by Side Diff: ui/views/view_unittest.cc

Issue 1166373008: views: Early out of painting Views with empty bounds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: emptyview: size Created 5 years, 6 months 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
« no previous file with comments | « ui/views/view.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 <map> 5 #include <map>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 } 425 }
426 426
427 //////////////////////////////////////////////////////////////////////////////// 427 ////////////////////////////////////////////////////////////////////////////////
428 // Painting 428 // Painting
429 //////////////////////////////////////////////////////////////////////////////// 429 ////////////////////////////////////////////////////////////////////////////////
430 430
431 void TestView::OnPaint(gfx::Canvas* canvas) { 431 void TestView::OnPaint(gfx::Canvas* canvas) {
432 did_paint_ = true; 432 did_paint_ = true;
433 } 433 }
434 434
435 TEST_F(ViewTest, PaintEmptyView) {
436 Widget* widget = new Widget;
437 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
438 widget->Init(params);
439 View* root_view = widget->GetRootView();
440 root_view->SetBounds(0, 0, 25, 26);
441
442 // |v1| is empty.
443 TestView* v1 = new TestView;
444 v1->SetBounds(10, 11, 0, 1);
445 root_view->AddChildView(v1);
446
447 // |v11| is a child of an empty |v1|.
448 TestView* v11 = new TestView;
449 v11->SetBounds(3, 4, 6, 5);
450 v1->AddChildView(v11);
451
452 // |v2| is not.
453 TestView* v2 = new TestView;
454 v2->SetBounds(3, 4, 6, 5);
455 root_view->AddChildView(v2);
456
457 // Paint "everything".
458 gfx::Rect first_paint(1, 1);
459 scoped_refptr<cc::DisplayItemList> list =
460 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings());
461 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint));
462
463 // The empty view has nothing to paint so it doesn't try build a cache, nor do
464 // its children which would be clipped by its (empty) self.
465 EXPECT_FALSE(v1->did_paint_);
466 EXPECT_FALSE(v11->did_paint_);
467 EXPECT_TRUE(v2->did_paint_);
468 }
469
435 TEST_F(ViewTest, PaintWithUnknownInvalidation) { 470 TEST_F(ViewTest, PaintWithUnknownInvalidation) {
436 Widget* widget = new Widget; 471 Widget* widget = new Widget;
437 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); 472 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
438 widget->Init(params); 473 widget->Init(params);
439 View* root_view = widget->GetRootView(); 474 View* root_view = widget->GetRootView();
440 root_view->SetBounds(0, 0, 25, 26); 475 root_view->SetBounds(0, 0, 25, 26);
441 476
442 TestView* v1 = new TestView; 477 TestView* v1 = new TestView;
443 v1->SetBounds(10, 11, 12, 13); 478 v1->SetBounds(10, 11, 12, 13);
444 root_view->AddChildView(v1); 479 root_view->AddChildView(v1);
(...skipping 3575 matching lines...) Expand 10 before | Expand all | Expand 10 after
4020 // notification. 4055 // notification.
4021 TestView* test_view_child_2 = new TestView(); 4056 TestView* test_view_child_2 = new TestView();
4022 test_view->AddChildView(test_view_child_2); 4057 test_view->AddChildView(test_view_child_2);
4023 EXPECT_TRUE(test_view_child_2->native_theme_); 4058 EXPECT_TRUE(test_view_child_2->native_theme_);
4024 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); 4059 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_);
4025 4060
4026 widget->CloseNow(); 4061 widget->CloseNow();
4027 } 4062 }
4028 4063
4029 } // namespace views 4064 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698