This source file includes following definitions.
- right_alpha_mask_
- Paint
- animation_offset_
- SetAnimationOffset
- OnPaint
- SetBackground
- SetBorderFromIds
#include "chrome/browser/ui/views/dropdown_bar_view.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkRect.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/painter.h"
#include "ui/views/widget/widget.h"
namespace {
const int kAnimatingEdgeHeight = 5;
class DropdownBackground : public views::Background {
public:
explicit DropdownBackground(BrowserView* browser,
const gfx::ImageSkia* left_alpha_mask,
const gfx::ImageSkia* right_alpha_mask);
virtual ~DropdownBackground() {}
virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE;
private:
BrowserView* browser_view_;
const gfx::ImageSkia* left_alpha_mask_;
const gfx::ImageSkia* right_alpha_mask_;
DISALLOW_COPY_AND_ASSIGN(DropdownBackground);
};
DropdownBackground::DropdownBackground(BrowserView* browser_view,
const gfx::ImageSkia* left_alpha_mask,
const gfx::ImageSkia* right_alpha_mask)
: browser_view_(browser_view),
left_alpha_mask_(left_alpha_mask),
right_alpha_mask_(right_alpha_mask) {
}
void DropdownBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
gfx::Point origin = view->GetWidget()->GetWindowBoundsInScreen().origin();
views::View::ConvertPointFromScreen(browser_view_, &origin);
origin = browser_view_->OffsetPointForToolbarBackgroundImage(origin);
ui::ThemeProvider* tp = view->GetThemeProvider();
gfx::ImageSkia background = *tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
int left_edge_width = left_alpha_mask_->width();
int right_edge_width = right_alpha_mask_->width();
int mask_height = left_alpha_mask_->height();
int height = view->bounds().height();
canvas->TileImageInt(background, origin.x(), origin.y(),
0, 0, view->bounds().width(), height);
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
canvas->DrawImageInt(*left_alpha_mask_, 0, 0, left_edge_width, mask_height,
0, 0, left_edge_width, height, false, paint);
int x_right_edge = view->bounds().width() - right_edge_width;
canvas->DrawImageInt(*right_alpha_mask_, 0, 0, right_edge_width,
mask_height, x_right_edge, 0, right_edge_width, height, false, paint);
}
}
DropdownBarView::DropdownBarView(DropdownBarHost* host)
: host_(host),
animation_offset_(0) {
}
DropdownBarView::~DropdownBarView() {
}
void DropdownBarView::SetAnimationOffset(int offset) {
animation_offset_ = offset;
set_clip_insets(gfx::Insets(animation_offset_, 0, 0, 0));
}
void DropdownBarView::OnPaint(gfx::Canvas* canvas) {
OnPaintBackground(canvas);
OnPaintBorder(canvas);
if (animation_offset() > 0) {
gfx::Canvas animating_edges(
gfx::Size(bounds().width(), kAnimatingEdgeHeight),
canvas->image_scale(),
false);
canvas->Translate(bounds().OffsetFromOrigin());
OnPaintBackground(&animating_edges);
OnPaintBorder(&animating_edges);
canvas->DrawImageInt(gfx::ImageSkia(animating_edges.ExtractImageRep()),
bounds().x(), animation_offset());
}
}
void DropdownBarView::SetBackground(const gfx::ImageSkia* left_alpha_mask,
const gfx::ImageSkia* right_alpha_mask) {
set_background(new DropdownBackground(host()->browser_view(), left_alpha_mask,
right_alpha_mask));
}
void DropdownBarView::SetBorderFromIds(int left_border_image_id,
int middle_border_image_id,
int right_border_image_id) {
int border_image_ids[3] = {left_border_image_id, middle_border_image_id,
right_border_image_id};
SetBorder(views::Border::CreateBorderPainter(
new views::HorizontalPainter(border_image_ids), gfx::Insets()));
}