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

Unified Diff: chrome/browser/views/extensions/extension_shelf.cc

Issue 215017: Fix extension toolstrip background update code (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/views/extensions/extension_shelf.h ('k') | chrome/browser/views/frame/browser_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/views/extensions/extension_shelf.cc
===================================================================
--- chrome/browser/views/extensions/extension_shelf.cc (revision 26491)
+++ chrome/browser/views/extensions/extension_shelf.cc (working copy)
@@ -480,7 +480,7 @@
}
int ExtensionShelf::Toolstrip::GetVerticalTearFromShelfThreshold() {
- // TODO (sidchat): Compute this value from the toolstrip height.
+ // TODO(sidchat): Compute this value from the toolstrip height.
return 29;
}
@@ -632,7 +632,6 @@
ExtensionShelf::ExtensionShelf(Browser* browser)
: background_needs_repaint_(true),
- background_for_detached_(false),
browser_(browser),
model_(browser->extension_shelf_model()) {
model_->AddObserver(this);
@@ -661,14 +660,7 @@
}
void ExtensionShelf::PaintChildren(gfx::Canvas* canvas) {
- // Capture a background bitmap to give to the toolstrips.
- SkRect background_rect = {
- SkIntToScalar(0),
- SkIntToScalar(0),
- SkIntToScalar(width()),
- SkIntToScalar(height())
- };
- InitBackground(canvas, background_rect);
+ InitBackground(canvas);
// Draw vertical dividers between Toolstrip items in the Extension shelf.
int count = GetChildViewCount();
@@ -746,8 +738,6 @@
}
void ExtensionShelf::ThemeChanged() {
- background_needs_repaint_ = true;
-
// Refresh the CSS to update toolstrip text colors from theme.
int count = model_->count();
for (int i = 0; i < count; ++i)
@@ -763,7 +753,6 @@
bool had_views = GetChildViewCount() > 0;
ExtensionView* view = host->view();
- background_needs_repaint_ = true;
AddChildView(view);
view->SetContainer(this);
if (!had_views)
@@ -832,7 +821,6 @@
if (browser_)
browser_->ExtensionShelfSizeChanged();
- background_needs_repaint_ = true;
Layout();
}
@@ -893,31 +881,26 @@
model_->CollapseToolstrip(toolstrip, url);
}
-void ExtensionShelf::InitBackground(
- gfx::Canvas* canvas, const SkRect& subset) {
- bool detached = IsDetached();
- if (!background_needs_repaint_ && background_for_detached_ == detached)
+void ExtensionShelf::InitBackground(gfx::Canvas* canvas) {
+ if (!background_needs_repaint_)
return;
- background_for_detached_ = detached;
+ // Capture a background bitmap to give to the toolstrips.
+ SkRect background_rect = {
+ SkIntToScalar(0),
+ SkIntToScalar(0),
+ SkIntToScalar(width()),
+ SkIntToScalar(height())
+ };
- // Tell all extension views about the new background
+ // Tell all extension views about the new background.
int count = model_->count();
for (int i = 0; i < count; ++i) {
ExtensionView* view = ToolstripAtIndex(i)->view();
const SkBitmap& background = canvas->getDevice()->accessBitmap(false);
- // Extract the correct subset of the toolstrip background into a bitmap. We
- // must use a temporary here because extractSubset() returns a bitmap that
- // references pixels in the original one and we want to actually make a copy
- // that will have a long lifetime.
- SkBitmap temp;
- temp.setConfig(background.config(),
- static_cast<int>(subset.width()),
- static_cast<int>(subset.height()));
-
- SkRect mapped_subset = subset;
+ SkRect mapped_subset = background_rect;
gfx::Rect view_bounds = view->bounds();
mapped_subset.offset(SkIntToScalar(view_bounds.x()),
SkIntToScalar(view_bounds.y()));
@@ -926,13 +909,22 @@
SkIRect isubset;
mapped_subset.round(&isubset);
- result = background.extractSubset(&temp, isubset);
+ SkBitmap subset_bitmap;
+ // This will create another bitmap that just references pixels in the
+ // actual bitmap.
+ result = background.extractSubset(&subset_bitmap, isubset);
if (!result)
return;
- DCHECK(temp.readyToDraw());
+ // We do a deep copy because extractSubset() returns a bitmap that
+ // references pixels in the original one and we want to actually make a
+ // smaller copy that will have a long lifetime.
+ SkBitmap smaller_copy;
+ if (!subset_bitmap.copyTo(&smaller_copy, SkBitmap::kARGB_8888_Config))
+ return;
+ DCHECK(smaller_copy.readyToDraw());
- view->SetBackground(temp);
+ view->SetBackground(smaller_copy);
}
background_needs_repaint_ = false;
@@ -1019,10 +1011,10 @@
x = next_x + kToolstripDividerWidth;
}
- if (!compute_bounds_only)
+ if (!compute_bounds_only) {
+ background_needs_repaint_ = true;
SchedulePaint();
-
- if (compute_bounds_only) {
+ } else {
if (OnNewTabPage()) {
prefsize.set_height(kShelfHeight + static_cast<int>(static_cast<double>
(kNewtabShelfHeight - kShelfHeight) *
« no previous file with comments | « chrome/browser/views/extensions/extension_shelf.h ('k') | chrome/browser/views/frame/browser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698