| Index: chrome/browser/views/extensions/extension_shelf.cc
|
| ===================================================================
|
| --- chrome/browser/views/extensions/extension_shelf.cc (revision 26222)
|
| +++ chrome/browser/views/extensions/extension_shelf.cc (working copy)
|
| @@ -19,6 +19,7 @@
|
| #include "chrome/browser/profile.h"
|
| #include "chrome/browser/tab_contents/tab_contents.h"
|
| #include "chrome/browser/views/extensions/extension_view.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/extensions/extension.h"
|
| #include "chrome/common/notification_service.h"
|
| #include "chrome/common/pref_names.h"
|
| @@ -45,7 +46,7 @@
|
| static const int kShelfHeight = 29;
|
|
|
| // Preferred height of the Extension shelf when only shown on the new tab page.
|
| -const int kNewtabShelfHeight = 57;
|
| +const int kNewtabShelfHeight = 58;
|
|
|
| // How inset the extension shelf is when displayed on the new tab page. This is
|
| // in addition to the margins above.
|
| @@ -58,32 +59,18 @@
|
| static const int kNewtabExtraHorMargin = 2;
|
| static const int kNewtabExtraVerMargin = 2;
|
|
|
| -// How round the 'new tab' style extension shelf is.
|
| -static const int kNewtabBarRoundness = 5;
|
| -
|
| // Height of the toolstrip within the shelf.
|
| static const int kToolstripHeight = kShelfHeight - (kTopMargin + kBottomMargin);
|
|
|
| // Colors for the ExtensionShelf.
|
| -static const SkColor kBackgroundColor = SkColorSetRGB(230, 237, 244);
|
| -static const SkColor kBorderColor = SkColorSetRGB(201, 212, 225);
|
| static const SkColor kDividerHighlightColor = SkColorSetRGB(247, 250, 253);
|
|
|
| -// Text colors for the handle.
|
| -static const SkColor kHandleTextColor = SkColorSetRGB(6, 45, 117);
|
| -static const SkColor kHandleTextHighlightColor =
|
| - SkColorSetARGB(200, 255, 255, 255);
|
| -
|
| // Handle padding.
|
| static const int kHandlePadding = 4;
|
|
|
| -// TODO(erikkay) convert back to a gradient when Glen figures out the
|
| -// specs.
|
| -// static const SkColor kBackgroundColor = SkColorSetRGB(237, 244, 252);
|
| -// static const SkColor kTopGradientColor = SkColorSetRGB(222, 234, 248);
|
| -
|
| // Delays for showing and hiding the shelf handle.
|
| -static const int kHideDelayMs = 500;
|
| +static const int kShowDelayMs = 500;
|
| +static const int kHideDelayMs = 300;
|
|
|
| } // namespace
|
|
|
| @@ -122,7 +109,7 @@
|
| // Convenience to calculate just the size of the handle.
|
| gfx::Size GetHandlePreferredSize();
|
|
|
| - // View
|
| + // View methods:
|
| virtual void Paint(gfx::Canvas* canvas);
|
| virtual gfx::Size GetPreferredSize();
|
| virtual void Layout();
|
| @@ -255,9 +242,6 @@
|
| // the various mouse events necessary for hovering and dragging.
|
| ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
| title_.reset(new views::Label(name, rb.GetFont(ResourceBundle::BaseFont)));
|
| - title_->SetColor(kHandleTextColor);
|
| - title_->SetDrawHighlighted(true);
|
| - title_->SetHighlightColor(kHandleTextHighlightColor);
|
| title_->SetBounds(kHandlePadding, kHandlePadding, 100, 100);
|
| title_->SizeToPreferredSize();
|
|
|
| @@ -270,14 +254,19 @@
|
| }
|
|
|
| void ExtensionShelf::Toolstrip::Paint(gfx::Canvas* canvas) {
|
| - canvas->FillRectInt(kBackgroundColor, 0, 0, width(), height());
|
| - canvas->FillRectInt(kBorderColor, 0, 0, width(), 1);
|
| - canvas->FillRectInt(kBorderColor, 0, 0, 1, height() - 1);
|
| - canvas->FillRectInt(kBorderColor, width() - 1, 0, 1, height() - 1);
|
| + // Paints the handle for the toolstrip (only called on mouse-hover).
|
| + SkColor theme_toolbar_color =
|
| + shelf_->GetThemeProvider()->GetColor(BrowserThemeProvider::COLOR_TOOLBAR);
|
| + canvas->FillRectInt(theme_toolbar_color, 0, 0, width(), height());
|
| +
|
| + SkColor border_color = ResourceBundle::toolbar_separator_color;
|
| + canvas->FillRectInt(border_color, 0, 0, width(), 1);
|
| + canvas->FillRectInt(border_color, 0, 0, 1, height() - 1);
|
| + canvas->FillRectInt(border_color, width() - 1, 0, 1, height() - 1);
|
| int ext_width = view()->width() + kToolstripPadding +
|
| kToolstripDividerWidth;
|
| if (ext_width < width()) {
|
| - canvas->FillRectInt(kBorderColor, ext_width, height() - 1,
|
| + canvas->FillRectInt(border_color, ext_width, height() - 1,
|
| width() - ext_width, 1);
|
| }
|
|
|
| @@ -286,8 +275,8 @@
|
| title_->ProcessPaint(canvas);
|
|
|
| if (dragging_) {
|
| - // when we're dragging, draw the bottom border.
|
| - canvas->FillRectInt(kBorderColor, 0, height() - 1, width(), 1);
|
| + // When we're dragging, draw the bottom border.
|
| + canvas->FillRectInt(border_color, 0, height() - 1, width(), 1);
|
| }
|
| }
|
|
|
| @@ -519,6 +508,11 @@
|
| void ExtensionShelf::Toolstrip::DoShowShelfHandle() {
|
| GetHandle();
|
| if (!handle_->visible()) {
|
| + // Make sure the text color for the title matches the theme colors.
|
| + title_->SetColor(
|
| + shelf_->GetThemeProvider()->GetColor(
|
| + BrowserThemeProvider::COLOR_BOOKMARK_TEXT));
|
| +
|
| LayoutHandle();
|
| handle_->Show();
|
| }
|
| @@ -596,7 +590,7 @@
|
| MessageLoop::current()->PostDelayedTask(FROM_HERE,
|
| timer_factory_.NewRunnableMethod(
|
| &ExtensionShelf::Toolstrip::DoShowShelfHandle),
|
| - 1000);
|
| + kShowDelayMs);
|
| }
|
|
|
| void ExtensionShelf::Toolstrip::HideShelfHandle(int delay_ms) {
|
| @@ -618,7 +612,9 @@
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| ExtensionShelf::ExtensionShelf(Browser* browser)
|
| - : browser_(browser),
|
| + : background_needs_repaint_(true),
|
| + background_for_detached_(false),
|
| + browser_(browser),
|
| model_(browser->extension_shelf_model()) {
|
| model_->AddObserver(this);
|
| LoadFromModel();
|
| @@ -645,95 +641,27 @@
|
| }
|
| }
|
|
|
| -void ExtensionShelf::Paint(gfx::Canvas* canvas) {
|
| - if (IsDetachedStyle()) {
|
| - // Draw the background to match the new tab page.
|
| - ThemeProvider* tp = GetThemeProvider();
|
| - canvas->FillRectInt(
|
| - tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND),
|
| - 0, 0, width(), height());
|
| +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);
|
|
|
| - // As 'hidden' according to the animation is the full in-tab state,
|
| - // we invert the value - when current_state is at '0', we expect the
|
| - // shelf to be docked.
|
| - double current_state = 1 - size_animation_->GetCurrentValue();
|
| -
|
| - // The 0.5 is to correct for Skia's "draw on pixel boundaries"ness.
|
| - double h_padding = static_cast<double>
|
| - (kNewtabHorizontalPadding) * current_state;
|
| - double v_padding = static_cast<double>
|
| - (kNewtabVerticalPadding) * current_state;
|
| - SkRect rect;
|
| - rect.set(SkDoubleToScalar(h_padding - 0.5),
|
| - SkDoubleToScalar(v_padding - 0.5),
|
| - SkDoubleToScalar(width() - h_padding - 0.5),
|
| - SkDoubleToScalar(height() - v_padding - 0.5));
|
| -
|
| - double roundness = static_cast<double>
|
| - (kNewtabBarRoundness) * current_state;
|
| -
|
| - // Draw the background behind the toolstrips.
|
| - SkPaint paint;
|
| - paint.setAntiAlias(true);
|
| - paint.setColor(kBackgroundColor);
|
| -
|
| - canvas->drawRoundRect(rect,
|
| - SkDoubleToScalar(roundness),
|
| - SkDoubleToScalar(roundness), paint);
|
| -
|
| - SkRect background_rect = {
|
| - SkIntToScalar(h_padding),
|
| - SkIntToScalar(v_padding + 2),
|
| - SkIntToScalar(h_padding + 1),
|
| - SkIntToScalar(v_padding + kToolstripHeight - 3)};
|
| - InitBackground(canvas, background_rect);
|
| -
|
| - // Draw the border around the toolstrips in the extension shelf.
|
| - SkPaint border_paint;
|
| - border_paint.setColor(
|
| - GetThemeProvider()->GetColor(BrowserThemeProvider::COLOR_NTP_HEADER));
|
| - border_paint.setStyle(SkPaint::kStroke_Style);
|
| - border_paint.setAlpha(96);
|
| - border_paint.setAntiAlias(true);
|
| - canvas->drawRoundRect(rect,
|
| - SkDoubleToScalar(roundness),
|
| - SkDoubleToScalar(roundness), border_paint);
|
| - } else {
|
| -#if 0
|
| - // TODO(erikkay) Re-enable when Glen has the gradient values worked out.
|
| - SkPaint paint;
|
| - paint.setShader(skia::CreateGradientShader(0,
|
| - height(),
|
| - kTopGradientColor,
|
| - kBackgroundColor))->safeUnref();
|
| - canvas->FillRectInt(0, 0, width(), height(), paint);
|
| -#else
|
| - canvas->FillRectInt(kBackgroundColor, 0, 0, width(), height());
|
| -#endif
|
| -
|
| - SkRect background_rect = {
|
| - SkIntToScalar(0),
|
| - SkIntToScalar(0),
|
| - SkIntToScalar(1),
|
| - SkIntToScalar(height())
|
| - };
|
| - InitBackground(canvas, background_rect);
|
| -
|
| - // Draw border around shelf in attached mode. If we are in detached mode
|
| - // we've already drawn the borders.
|
| - canvas->FillRectInt(kBorderColor, 0, 0, width(), 1);
|
| - canvas->FillRectInt(kBorderColor, 0, height() - 1, width(), 1);
|
| - }
|
| -
|
| // Draw vertical dividers between Toolstrip items in the Extension shelf.
|
| int count = GetChildViewCount();
|
| for (int i = 0; i < count; ++i) {
|
| int right = GetChildViewAt(i)->bounds().right() + kToolstripPadding;
|
| - int y = IsDetachedStyle() ? kNewtabVerticalPadding : 1;
|
| - int h = IsDetachedStyle() ? height() - (2 * kNewtabVerticalPadding) - 1:
|
| - height() - 2;
|
| - canvas->FillRectInt(kBorderColor, right, y, 1, h);
|
| - canvas->FillRectInt(kDividerHighlightColor, right + 1, y, 1, h);
|
| + int vertical_padding = IsDetached() ? (height() - kShelfHeight) / 2 : 1;
|
| +
|
| + DetachableToolbarView::PaintVerticalDivider(
|
| + canvas, right, height(), vertical_padding,
|
| + SK_ColorWHITE,
|
| + kDividerHighlightColor,
|
| + GetThemeProvider()->GetColor(BrowserThemeProvider::COLOR_TOOLBAR));
|
| }
|
| }
|
|
|
| @@ -771,7 +699,6 @@
|
| LayoutItems(false);
|
| }
|
|
|
| -
|
| void ExtensionShelf::OnMouseEntered(const views::MouseEvent& event) {
|
| }
|
|
|
| @@ -799,6 +726,17 @@
|
| accessible_name_.assign(name);
|
| }
|
|
|
| +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)
|
| + ToolstripAtIndex(i)->view()->host()->InsertCssIfToolstrip();
|
| +
|
| + Layout();
|
| +}
|
| +
|
| void ExtensionShelf::ToolstripInsertedAt(ExtensionHost* host,
|
| int index) {
|
| model_->SetToolstripDataAt(index,
|
| @@ -806,8 +744,7 @@
|
|
|
| bool had_views = GetChildViewCount() > 0;
|
| ExtensionView* view = host->view();
|
| - if (!background_.empty())
|
| - view->SetBackground(background_);
|
| + background_needs_repaint_ = true;
|
| AddChildView(view);
|
| view->SetContainer(this);
|
| if (!had_views)
|
| @@ -876,7 +813,8 @@
|
| if (browser_)
|
| browser_->ExtensionShelfSizeChanged();
|
|
|
| - SchedulePaint();
|
| + background_needs_repaint_ = true;
|
| + Layout();
|
| }
|
|
|
| void ExtensionShelf::Observe(NotificationType type,
|
| @@ -936,38 +874,49 @@
|
| model_->CollapseToolstrip(toolstrip, url);
|
| }
|
|
|
| -void ExtensionShelf::InitBackground(gfx::Canvas* canvas, const SkRect& subset) {
|
| - if (!background_.empty())
|
| +void ExtensionShelf::InitBackground(
|
| + gfx::Canvas* canvas, const SkRect& subset) {
|
| + bool detached = IsDetached();
|
| + if (!background_needs_repaint_ && background_for_detached_ == detached)
|
| return;
|
|
|
| - const SkBitmap& background = canvas->getDevice()->accessBitmap(false);
|
| + background_for_detached_ = detached;
|
|
|
| - // 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()));
|
| + // Tell all extension views about the new background
|
| + int count = model_->count();
|
| + for (int i = 0; i < count; ++i) {
|
| + ExtensionView* view = ToolstripAtIndex(i)->view();
|
|
|
| - SkRect mapped_subset = subset;
|
| - bool result = canvas->getTotalMatrix().mapRect(&mapped_subset);
|
| - DCHECK(result);
|
| + const SkBitmap& background = canvas->getDevice()->accessBitmap(false);
|
|
|
| - SkIRect isubset;
|
| - mapped_subset.round(&isubset);
|
| - result = background.extractSubset(&temp, isubset);
|
| - if (!result)
|
| - return;
|
| + // 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()));
|
|
|
| - temp.copyTo(&background_, temp.config());
|
| - DCHECK(background_.readyToDraw());
|
| + SkRect mapped_subset = subset;
|
| + gfx::Rect view_bounds = view->bounds();
|
| + mapped_subset.offset(SkIntToScalar(view_bounds.x()),
|
| + SkIntToScalar(view_bounds.y()));
|
| + bool result = canvas->getTotalMatrix().mapRect(&mapped_subset);
|
| + DCHECK(result);
|
|
|
| - // Tell all extension views about the new background
|
| - int count = model_->count();
|
| - for (int i = 0; i < count; ++i)
|
| - ToolstripAtIndex(i)->view()->SetBackground(background_);
|
| + SkIRect isubset;
|
| + mapped_subset.round(&isubset);
|
| + result = background.extractSubset(&temp, isubset);
|
| + if (!result)
|
| + return;
|
| +
|
| + DCHECK(temp.readyToDraw());
|
| +
|
| + view->SetBackground(temp);
|
| + }
|
| +
|
| + background_needs_repaint_ = false;
|
| }
|
|
|
| ExtensionShelf::Toolstrip* ExtensionShelf::ToolstripAtX(int x) {
|
| @@ -1033,13 +982,13 @@
|
|
|
| int count = model_->count();
|
| for (int i = 0; i < count; ++i) {
|
| - x += kToolstripPadding; // left padding
|
| + x += kToolstripPadding; // Left padding.
|
| Toolstrip* toolstrip = ToolstripAtIndex(i);
|
| - if (!toolstrip) // can be NULL while in the process of removing
|
| + if (!toolstrip) // Can be NULL while in the process of removing.
|
| continue;
|
| View* view = toolstrip->GetShelfView();
|
| gfx::Size pref = view->GetPreferredSize();
|
| - int next_x = x + pref.width() + kToolstripPadding; // right padding
|
| + int next_x = x + pref.width() + kToolstripPadding; // Right padding.
|
| if (!compute_bounds_only) {
|
| if (view == toolstrip->view())
|
| toolstrip->view()->set_is_clipped(next_x >= max_x);
|
| @@ -1071,16 +1020,22 @@
|
| return prefsize;
|
| }
|
|
|
| -bool ExtensionShelf::IsDetachedStyle() {
|
| +bool ExtensionShelf::IsOnTop() const {
|
| + static bool is_on_top = CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kShowExtensionsOnTop);
|
| + return is_on_top;
|
| +}
|
| +
|
| +bool ExtensionShelf::IsDetached() const {
|
| return OnNewTabPage() && (size_animation_->GetCurrentValue() != 1);
|
| }
|
|
|
| -bool ExtensionShelf::IsAlwaysShown() {
|
| +bool ExtensionShelf::IsAlwaysShown() const {
|
| Profile* profile = browser_->profile();
|
| return profile->GetPrefs()->GetBoolean(prefs::kShowExtensionShelf);
|
| }
|
|
|
| -bool ExtensionShelf::OnNewTabPage() {
|
| +bool ExtensionShelf::OnNewTabPage() const {
|
| return (browser_ && browser_->GetSelectedTabContents() &&
|
| browser_->GetSelectedTabContents()->IsExtensionShelfAlwaysVisible());
|
| }
|
|
|