Commit 8bbc59b5 authored by bruthig's avatar bruthig Committed by Commit bot

Fixed BubbleBorder sizing problems & added unit tests.

BUG=395622

TEST=automated

Review URL: https://codereview.chromium.org/454173002

Cr-Commit-Position: refs/heads/master@{#292145}
parent 38b5bea9
......@@ -91,8 +91,8 @@ class WebNotificationBubbleWrapper {
}
views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create(
tray->GetBubbleWindowContainer(), anchor, tray, &init_params);
bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view));
bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
bubble->InitializeContents(bubble_view);
}
......
......@@ -7,10 +7,8 @@
#include <algorithm>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/skia_util.h"
#include "ui/resources/grit/ui_resources.h"
......@@ -21,31 +19,6 @@ namespace views {
namespace internal {
// A helper that combines each border image-set painter with arrows and metrics.
struct BorderImages {
BorderImages(const int border_image_ids[],
const int arrow_image_ids[],
int border_interior_thickness,
int arrow_interior_thickness,
int corner_radius);
scoped_ptr<Painter> border_painter;
gfx::ImageSkia left_arrow;
gfx::ImageSkia top_arrow;
gfx::ImageSkia right_arrow;
gfx::ImageSkia bottom_arrow;
// The thickness of border and arrow images and their interior areas.
// Thickness is the width of left/right and the height of top/bottom images.
// The interior is measured without including stroke or shadow pixels.
int border_thickness;
int border_interior_thickness;
int arrow_thickness;
int arrow_interior_thickness;
// The corner radius of the bubble's rounded-rect interior area.
int corner_radius;
};
BorderImages::BorderImages(const int border_image_ids[],
const int arrow_image_ids[],
int border_interior_thickness,
......@@ -68,13 +41,12 @@ BorderImages::BorderImages(const int border_image_ids[],
}
}
BorderImages::~BorderImages() {}
} // namespace internal
namespace {
// The border and arrow stroke size used in image assets, in pixels.
const int kStroke = 1;
// Bubble border and arrow image resource ids. They don't use the IMAGE_GRID
// macro because there is no center image.
const int kNoShadowImages[] = {
......@@ -150,6 +122,8 @@ BorderImages* GetBorderImages(BubbleBorder::Shadow shadow) {
} // namespace
const int BubbleBorder::kStroke = 1;
BubbleBorder::BubbleBorder(Arrow arrow, Shadow shadow, SkColor color)
: arrow_(arrow),
arrow_offset_(0),
......@@ -278,7 +252,7 @@ gfx::Size BubbleBorder::GetSizeForContentsSize(
std::max(images_->arrow_thickness + images_->border_interior_thickness,
images_->border_thickness);
// Only take arrow image sizes into account when the bubble tip is shown.
if (arrow_paint_type_ == PAINT_TRANSPARENT || !has_arrow(arrow_))
if (arrow_paint_type_ == PAINT_NONE || !has_arrow(arrow_))
size.SetToMax(gfx::Size(min, min));
else if (is_arrow_on_horizontal(arrow_))
size.SetToMax(gfx::Size(min_with_arrow_width, min_with_arrow_thickness));
......@@ -360,6 +334,10 @@ void BubbleBorder::DrawArrow(gfx::Canvas* canvas,
canvas->DrawPath(path, paint);
}
internal::BorderImages* BubbleBorder::GetImagesForTest() const {
return images_;
}
void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
if (border_->shadow() == BubbleBorder::NO_SHADOW_OPAQUE_BORDER)
canvas->DrawColor(border_->background_color());
......
......@@ -7,19 +7,47 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
namespace gfx {
class ImageSkia;
class Rect;
}
namespace views {
class Painter;
namespace internal {
struct BorderImages;
}
// A helper that combines each border image-set painter with arrows and metrics.
struct BorderImages {
BorderImages(const int border_image_ids[],
const int arrow_image_ids[],
int border_interior_thickness,
int arrow_interior_thickness,
int corner_radius);
virtual ~BorderImages();
scoped_ptr<Painter> border_painter;
gfx::ImageSkia left_arrow;
gfx::ImageSkia top_arrow;
gfx::ImageSkia right_arrow;
gfx::ImageSkia bottom_arrow;
// The thickness of border and arrow images and their interior areas.
// Thickness is the width of left/right and the height of top/bottom images.
// The interior is measured without including stroke or shadow pixels.
int border_thickness;
int border_interior_thickness;
int arrow_thickness;
int arrow_interior_thickness;
// The corner radius of the bubble's rounded-rect interior area.
int corner_radius;
};
} // namespace internal
// Renders a border, with optional arrow, and a custom dropshadow.
// This can be used to produce floating "bubble" objects with rounded corners.
......@@ -173,11 +201,19 @@ class VIEWS_EXPORT BubbleBorder : public Border {
virtual gfx::Size GetMinimumSize() const OVERRIDE;
private:
FRIEND_TEST_ALL_PREFIXES(BubbleBorderTest, GetSizeForContentsSizeTest);
FRIEND_TEST_ALL_PREFIXES(BubbleBorderTest, GetBoundsOriginTest);
// The border and arrow stroke size used in image assets, in pixels.
static const int kStroke;
gfx::Size GetSizeForContentsSize(const gfx::Size& contents_size) const;
gfx::ImageSkia* GetArrowImage() const;
gfx::Rect GetArrowRect(const gfx::Rect& bounds) const;
void DrawArrow(gfx::Canvas* canvas, const gfx::Rect& arrow_bounds) const;
internal::BorderImages* GetImagesForTest() const;
Arrow arrow_;
int arrow_offset_;
ArrowPaintType arrow_paint_type_;
......
This diff is collapsed.
......@@ -58,7 +58,6 @@ class MouseMoveDetectorHost : public MouseWatcherHost {
virtual bool Contains(const gfx::Point& screen_point,
MouseEventType type) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(MouseMoveDetectorHost);
};
......@@ -382,6 +381,7 @@ void TrayBubbleView::SetWidth(int width) {
void TrayBubbleView::SetArrowPaintType(
views::BubbleBorder::ArrowPaintType paint_type) {
bubble_border_->set_paint_arrow(paint_type);
UpdateBubble();
}
gfx::Insets TrayBubbleView::GetBorderInsets() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment