diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 17:18:40 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 17:18:40 +0000 |
commit | 1fdfce6867010e31e52198e996ab0d05703dacf5 (patch) | |
tree | a911542bfa508afdb4bb899cd454d28a16fc6729 | |
parent | ffaef0ca68c27e10935be966b3660fb5ecd897b8 (diff) | |
download | chromium_src-1fdfce6867010e31e52198e996ab0d05703dacf5.zip chromium_src-1fdfce6867010e31e52198e996ab0d05703dacf5.tar.gz chromium_src-1fdfce6867010e31e52198e996ab0d05703dacf5.tar.bz2 |
Fix build. When I recreated my changelist I accidentally left out two files I had added.
Fixing.
TBR=jcampan
BUG=None
TEST=Build should work
Review URL: http://codereview.chromium.org/204023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26228 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/views/detachable_toolbar_view.cc | 262 | ||||
-rw-r--r-- | chrome/browser/views/detachable_toolbar_view.h | 98 |
2 files changed, 360 insertions, 0 deletions
diff --git a/chrome/browser/views/detachable_toolbar_view.cc b/chrome/browser/views/detachable_toolbar_view.cc new file mode 100644 index 0000000..9cc81d2 --- /dev/null +++ b/chrome/browser/views/detachable_toolbar_view.cc @@ -0,0 +1,262 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/views/detachable_toolbar_view.h" + +#include "app/gfx/canvas.h" +#include "chrome/browser/browser_theme_provider.h" +#include "grit/theme_resources.h" +#include "third_party/skia/include/core/SkBitmap.h" + +// How round the 'new tab' style bookmarks bar is. +static const int kNewtabBarRoundness = 5; + +// static +void DetachableToolbarView::PaintBackgroundDetachedMode(gfx::Canvas* canvas, + views::View* view) { + int browser_height = view->GetParent()->GetBounds( + views::View::APPLY_MIRRORING_TRANSFORMATION).height(); + + // Draw the background to match the new tab page. + ThemeProvider* tp = view->GetThemeProvider(); + canvas->FillRectInt(tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND), + 0, 0, view->width(), view->height()); + + if (tp->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { + int tiling = BrowserThemeProvider::NO_REPEAT; + tp->GetDisplayProperty(BrowserThemeProvider::NTP_BACKGROUND_TILING, + &tiling); + int alignment; + if (tp->GetDisplayProperty(BrowserThemeProvider::NTP_BACKGROUND_ALIGNMENT, + &alignment)) { + SkBitmap* ntp_background = tp->GetBitmapNamed(IDR_THEME_NTP_BACKGROUND); + + if (alignment & BrowserThemeProvider::ALIGN_TOP) { + PaintThemeBackgroundTopAligned( + canvas, ntp_background, tiling, alignment, + view->width(), view->height()); + } else { + PaintThemeBackgroundBottomAligned( + canvas, ntp_background, tiling, alignment, + view->width(), view->height(), browser_height); + } + } + } +} + +// static +void DetachableToolbarView::PaintBackgroundAttachedMode(gfx::Canvas* canvas, + views::View* view) { + gfx::Rect bounds = + view->GetBounds(views::View::APPLY_MIRRORING_TRANSFORMATION); + + ThemeProvider* tp = view->GetThemeProvider(); + SkColor theme_toolbar_color = + tp->GetColor(BrowserThemeProvider::COLOR_TOOLBAR); + canvas->FillRectInt(theme_toolbar_color, 0, 0, + view->width(), view->height()); + + canvas->TileImageInt(*tp->GetBitmapNamed(IDR_THEME_TOOLBAR), + view->GetParent()->GetBounds( + views::View::APPLY_MIRRORING_TRANSFORMATION).x() + bounds.x(), + bounds.y(), 0, 0, view->width(), view->height()); +} + +// static +void DetachableToolbarView::CalculateContentArea( + double animation_state, double horizontal_padding, + double vertical_padding, SkRect* rect, + double* roundness, views::View* view) { + // The 0.5 is to correct for Skia's "draw on pixel boundaries"ness. + rect->set(SkDoubleToScalar(horizontal_padding - 0.5), + SkDoubleToScalar(vertical_padding - 0.5), + SkDoubleToScalar(view->width() - horizontal_padding - 0.5), + SkDoubleToScalar(view->height() - vertical_padding - 0.5)); + + *roundness = static_cast<double>(kNewtabBarRoundness) * animation_state; +} + +// static +void DetachableToolbarView::PaintHorizontalBorder(gfx::Canvas* canvas, + DetachableToolbarView* view) { + // Border can be at the top or at the bottom of the view depending on whether + // the view (bar/shelf) is at the top/at the bottom and whether it is attached + // or detached. + int y = view->IsOnTop() == !view->IsDetached() ? view->height() - 1 : 0; + canvas->FillRectInt(ResourceBundle::toolbar_separator_color, + 0, y, view->width(), 1); +} + +// static +void DetachableToolbarView::PaintContentAreaBackground( + gfx::Canvas* canvas, ThemeProvider* theme_provider, + const SkRect& rect, double roundness) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(theme_provider->GetColor(BrowserThemeProvider::COLOR_TOOLBAR)); + + canvas->drawRoundRect( + rect, SkDoubleToScalar(roundness), SkDoubleToScalar(roundness), paint); +} + +// static +void DetachableToolbarView::PaintContentAreaBorder( + gfx::Canvas* canvas, ThemeProvider* theme_provider, + const SkRect& rect, double roundness) { + SkPaint border_paint; + border_paint.setColor( + theme_provider->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); +} + +// static +void DetachableToolbarView::PaintVerticalDivider( + gfx::Canvas* canvas, int x, int height, int vertical_padding, + const SkColor& top_color, + const SkColor& middle_color, + const SkColor& bottom_color) { + // Draw the upper half of the divider. + SkPaint paint; + paint.setShader(skia::CreateGradientShader(vertical_padding + 1, + height / 2, + top_color, + middle_color))->safeUnref(); + SkRect rc = { SkIntToScalar(x), + SkIntToScalar(vertical_padding + 1), + SkIntToScalar(x + 1), + SkIntToScalar(height / 2) }; + canvas->drawRect(rc, paint); + + // Draw the lower half of the divider. + SkPaint paint_down; + paint_down.setShader(skia::CreateGradientShader(height / 2, + height - vertical_padding, + middle_color, + bottom_color))->safeUnref(); + SkRect rc_down = { SkIntToScalar(x), + SkIntToScalar(height / 2), + SkIntToScalar(x + 1), + SkIntToScalar(height - vertical_padding) }; + canvas->drawRect(rc_down, paint_down); +} + +// static +void DetachableToolbarView::PaintThemeBackgroundTopAligned( + gfx::Canvas* canvas, SkBitmap* ntp_background, int tiling, int alignment, + int width, int height) { + if (alignment & BrowserThemeProvider::ALIGN_LEFT) { + if (tiling == BrowserThemeProvider::REPEAT) { + canvas->TileImageInt(*ntp_background, 0, 0, width, height); + } else if (tiling == BrowserThemeProvider::REPEAT_X) { + canvas->TileImageInt(*ntp_background, 0, 0, width, + ntp_background->height()); + } else { + canvas->TileImageInt(*ntp_background, 0, 0, + ntp_background->width(), ntp_background->height()); + } + } else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) { + int x_pos = width % ntp_background->width() - ntp_background->width(); + if (tiling == BrowserThemeProvider::REPEAT) { + canvas->TileImageInt(*ntp_background, x_pos, 0, + width + ntp_background->width(), height); + } else if (tiling == BrowserThemeProvider::REPEAT_X) { + canvas->TileImageInt(*ntp_background, x_pos, + 0, width + ntp_background->width(), ntp_background->height()); + } else { + canvas->TileImageInt(*ntp_background, width - ntp_background->width(), + 0, ntp_background->width(), ntp_background->height()); + } + } else { // ALIGN == CENTER + int x_pos = width > ntp_background->width() ? + ((width / 2 - ntp_background->width() / 2) % + ntp_background->width()) - ntp_background->width() : + width / 2 - ntp_background->width() / 2; + if (tiling == BrowserThemeProvider::REPEAT) { + canvas->TileImageInt(*ntp_background, x_pos, 0, + width + ntp_background->width(), height); + } else if (tiling == BrowserThemeProvider::REPEAT_X) { + canvas->TileImageInt(*ntp_background, x_pos, 0, + width + ntp_background->width(), + ntp_background->height()); + } else { + canvas->TileImageInt(*ntp_background, + width / 2 - ntp_background->width() / 2, + 0, ntp_background->width(), ntp_background->height()); + } + } +} + +// static +void DetachableToolbarView::PaintThemeBackgroundBottomAligned( + gfx::Canvas* canvas, SkBitmap* ntp_background, int tiling, int alignment, + int width, int height, int browser_height) { + int border_width = 5; + int y_pos = ((tiling == BrowserThemeProvider::REPEAT_X) || + (tiling == BrowserThemeProvider::NO_REPEAT)) ? + browser_height - ntp_background->height() - height - border_width : + browser_height % ntp_background->height() - height - border_width - + ntp_background->height(); + + if (alignment & BrowserThemeProvider::ALIGN_LEFT) { + if (tiling == BrowserThemeProvider::REPEAT) { + canvas->TileImageInt(*ntp_background, 0, y_pos, width, + 2 * height + ntp_background->height() + 5); + } else if (tiling == BrowserThemeProvider::REPEAT_X) { + canvas->TileImageInt(*ntp_background, 0, y_pos, width, + ntp_background->height()); + } else if (tiling == BrowserThemeProvider::REPEAT_Y) { + canvas->TileImageInt(*ntp_background, 0, y_pos, + ntp_background->width(), + 2 * height + ntp_background->height() + 5); + } else { + canvas->TileImageInt(*ntp_background, 0, y_pos, ntp_background->width(), + ntp_background->height()); + } + } else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) { + int x_pos = width % ntp_background->width() - ntp_background->width(); + if (tiling == BrowserThemeProvider::REPEAT) { + canvas->TileImageInt(*ntp_background, x_pos, y_pos, + width + ntp_background->width(), + 2 * height + ntp_background->height() + 5); + } else if (tiling == BrowserThemeProvider::REPEAT_X) { + canvas->TileImageInt(*ntp_background, x_pos, y_pos, + width + ntp_background->width(), ntp_background->height()); + } else if (tiling == BrowserThemeProvider::REPEAT_Y) { + canvas->TileImageInt(*ntp_background, width - ntp_background->width(), + y_pos, ntp_background->width(), + 2 * height + ntp_background->height() + 5); + } else { + canvas->TileImageInt(*ntp_background, width - ntp_background->width(), + y_pos, ntp_background->width(), ntp_background->height()); + } + } else { // ALIGN == CENTER + int x_pos = width > ntp_background->width() ? + ((width / 2 - ntp_background->width() / 2) % + ntp_background->width()) - ntp_background->width() : + width / 2 - ntp_background->width() / 2; + if (tiling == BrowserThemeProvider::REPEAT) { + canvas->TileImageInt(*ntp_background, x_pos, y_pos, + width + ntp_background->width(), + 2 * height + ntp_background->height() + 5); + } else if (tiling == BrowserThemeProvider::REPEAT_X) { + canvas->TileImageInt(*ntp_background, x_pos, y_pos, + width + ntp_background->width(), ntp_background->height()); + } else if (tiling == BrowserThemeProvider::REPEAT_Y) { + canvas->TileImageInt(*ntp_background, + width / 2 - ntp_background->width() / 2, + y_pos, ntp_background->width(), + 2 * height + ntp_background->height() + 5); + } else { + canvas->TileImageInt(*ntp_background, + width / 2 - ntp_background->width() / 2, + y_pos, ntp_background->width(), ntp_background->height()); + } + } +} diff --git a/chrome/browser/views/detachable_toolbar_view.h b/chrome/browser/views/detachable_toolbar_view.h new file mode 100644 index 0000000..f831ea1 --- /dev/null +++ b/chrome/browser/views/detachable_toolbar_view.h @@ -0,0 +1,98 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_DETACHABLE_TOOLBAR_VIEW_H_ +#define CHROME_BROWSER_VIEWS_DETACHABLE_TOOLBAR_VIEW_H_ + +#include "views/view.h" + +class SkBitmap; +struct SkRect; + +// DetachableToolbarView contains functionality common to views that can detach +// from the Chrome frame, such as the BookmarkBarView and the Extension shelf. +class DetachableToolbarView : public views::View { + public: + DetachableToolbarView() {} + virtual ~DetachableToolbarView() {} + + // Whether the view is currently detached from the Chrome frame. + virtual bool IsDetached() const = 0; + + // Whether the shelf/bar is above the page or below it. + virtual bool IsOnTop() const = 0; + + // Gets the current state of the resize animation (show/hide). + virtual double GetAnimationValue() const = 0; + + // Paint the background (including the theme image behind content area) when + // in bar/shelf is detached from the Chrome frame. + static void PaintBackgroundDetachedMode(gfx::Canvas* canvas, + views::View* view); + + // Paint the background (including the theme image behind content area) when + // in bar/shelf is attached to the Chrome frame. + static void PaintBackgroundAttachedMode(gfx::Canvas* canvas, + views::View* view); + + // Calculate the rect for the content area of the bar/shelf. This is only + // needed when the bar/shelf is detached from the Chrome frame (otherwise the + // content area is the whole area of the bar/shelf. When detached, however, + // only a small round rectangle is for drawing our content on. This calculates + // how big this area is, where it is located within the shelf and how round + // the edges should be. + static void CalculateContentArea(double animation_state, + double horizontal_padding, + double vertical_padding, + SkRect* rect, + double* roundness, + views::View* view); + + // Paint the horizontal border separating the shelf/bar from the page content. + static void PaintHorizontalBorder(gfx::Canvas* canvas, + DetachableToolbarView* view); + + // Paint the background of the content area (the surface behind the + // bookmarks or extension toolstrips). |rect| is the rectangle to paint + // the background within. |roundness| describes the roundness of the corners. + static void PaintContentAreaBackground(gfx::Canvas* canvas, + ThemeProvider* theme_provider, + const SkRect& rect, + double roundness); + // Paint the border around the content area (when in detached mode). + static void PaintContentAreaBorder(gfx::Canvas* canvas, + ThemeProvider* theme_provider, + const SkRect& rect, + double roundness); + + // Paint a themed gradient divider at location |x|. The color of the divider + // is a gradient starting with |top_color| at the top, and changing into + // |middle_color| and then over to |bottom_color| as you go further down. + static void PaintVerticalDivider(gfx::Canvas* canvas, + int x, + int height, + int vertical_padding, + const SkColor& top_color, + const SkColor& middle_color, + const SkColor& bottom_color); + + // Paint the theme background with the proper alignment. + static void PaintThemeBackgroundTopAligned(gfx::Canvas* canvas, + SkBitmap* ntp_background, + int tiling, + int alignment, + int width, + int height); + static void PaintThemeBackgroundBottomAligned(gfx::Canvas* canvas, + SkBitmap* ntp_background, + int tiling, + int alignment, + int width, + int height, + int browser_height); + private: + DISALLOW_COPY_AND_ASSIGN(DetachableToolbarView); +}; + +#endif // CHROME_BROWSER_VIEWS_DETACHABLE_TOOLBAR_VIEW_H_ |