Commit c90126cf authored by calamity's avatar calamity Committed by Commit bot

Make ShadowBorder use ShadowValue.

This CL makes ShadowBorder depend on ShadowValue more rather than doing
independent calculations. It also adds a constructor that takes a
ShadowValue.

BUG=None

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

Cr-Commit-Position: refs/heads/master@{#315250}
parent 288f7262
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/ui/views/message_center/message_center_frame_view.h" #include "chrome/browser/ui/views/message_center/message_center_frame_view.h"
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/gfx/shadow_value.h"
#include "ui/message_center/message_center_style.h" #include "ui/message_center/message_center_style.h"
#include "ui/views/shadow_border.h" #include "ui/views/shadow_border.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -19,10 +20,8 @@ MessageCenterFrameView::MessageCenterFrameView() { ...@@ -19,10 +20,8 @@ MessageCenterFrameView::MessageCenterFrameView() {
#else #else
const int kShadowBlur = 8; const int kShadowBlur = 8;
SetBorder(scoped_ptr<views::Border>(new views::ShadowBorder( SetBorder(scoped_ptr<views::Border>(new views::ShadowBorder(
kShadowBlur, gfx::ShadowValue(gfx::Point(0, 0), kShadowBlur,
message_center::kMessageCenterShadowColor, message_center::kMessageCenterShadowColor))));
0, // Vertical offset
0))); // Horizontal offset
#endif #endif
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/shadow_value.h"
#include "ui/resources/grit/ui_resources.h" #include "ui/resources/grit/ui_resources.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
...@@ -85,8 +86,8 @@ SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, ...@@ -85,8 +86,8 @@ SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
AddChildView(content_container_); AddChildView(content_container_);
if (switches::IsExperimentalAppListEnabled()) { if (switches::IsExperimentalAppListEnabled()) {
SetBorder(make_scoped_ptr( SetBorder(make_scoped_ptr(new views::ShadowBorder(gfx::ShadowValue(
new views::ShadowBorder(kShadowBlur, kShadowColor, kShadowYOffset, 0))); gfx::Point(0, kShadowYOffset), kShadowBlur, kShadowColor))));
back_button_ = new views::ImageButton(this); back_button_ = new views::ImageButton(this);
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
back_button_->SetImage( back_button_->SetImage(
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ui/app_list/views/app_list_main_view.h" #include "ui/app_list/views/app_list_main_view.h"
#include "ui/app_list/views/search_result_list_view.h" #include "ui/app_list/views/search_result_list_view.h"
#include "ui/app_list/views/search_result_tile_item_list_view.h" #include "ui/app_list/views/search_result_tile_item_list_view.h"
#include "ui/gfx/shadow_value.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
...@@ -28,7 +29,8 @@ class SearchCardView : public views::View { ...@@ -28,7 +29,8 @@ class SearchCardView : public views::View {
public: public:
explicit SearchCardView(views::View* content_view) { explicit SearchCardView(views::View* content_view) {
SetBorder(make_scoped_ptr(new views::ShadowBorder( SetBorder(make_scoped_ptr(new views::ShadowBorder(
kCardShadowBlur, kCardShadowColor, kCardShadowYOffset, 0))); gfx::ShadowValue(gfx::Point(0, kCardShadowYOffset), kCardShadowBlur,
kCardShadowColor))));
SetLayoutManager(new views::FillLayout()); SetLayoutManager(new views::FillLayout());
content_view->set_background( content_view->set_background(
views::Background::CreateSolidBackground(kCardBackgroundColor)); views::Background::CreateSolidBackground(kCardBackgroundColor));
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/path.h" #include "ui/gfx/path.h"
#include "ui/gfx/shadow_value.h"
#include "ui/resources/grit/ui_resources.h" #include "ui/resources/grit/ui_resources.h"
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
#include "ui/views/animation/bounds_animator.h" #include "ui/views/animation/bounds_animator.h"
...@@ -108,10 +109,8 @@ bool MicButton::GetHitTestMask(gfx::Path* mask) const { ...@@ -108,10 +109,8 @@ bool MicButton::GetHitTestMask(gfx::Path* mask) const {
SpeechView::SpeechView(AppListViewDelegate* delegate) SpeechView::SpeechView(AppListViewDelegate* delegate)
: delegate_(delegate), : delegate_(delegate),
logo_(NULL) { logo_(NULL) {
SetBorder(scoped_ptr<views::Border>( SetBorder(scoped_ptr<views::Border>(new views::ShadowBorder(gfx::ShadowValue(
new views::ShadowBorder(kCardShadowBlur, kCardShadowColor, gfx::Point(0, kCardShadowYOffset), kCardShadowBlur, kCardShadowColor))));
kCardShadowYOffset, // Vertical offset.
0)));
// To keep the painting order of the border and the background, this class // To keep the painting order of the border and the background, this class
// actually has a single child of 'container' which has white background and // actually has a single child of 'container' which has white background and
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/shadow_value.h"
#include "ui/message_center/message_center.h" #include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_style.h" #include "ui/message_center/message_center_style.h"
#include "ui/message_center/views/padded_button.h" #include "ui/message_center/views/padded_button.h"
...@@ -126,11 +127,9 @@ gfx::Insets MessageView::GetShadowInsets() { ...@@ -126,11 +127,9 @@ gfx::Insets MessageView::GetShadowInsets() {
} }
void MessageView::CreateShadowBorder() { void MessageView::CreateShadowBorder() {
SetBorder(scoped_ptr<views::Border>( SetBorder(scoped_ptr<views::Border>(new views::ShadowBorder(
new views::ShadowBorder(kShadowBlur, gfx::ShadowValue(gfx::Point(0, kShadowOffset), kShadowBlur,
message_center::kShadowColor, message_center::kShadowColor))));
kShadowOffset, // Vertical offset.
0))); // Horizontal offset.
} }
bool MessageView::IsCloseButtonFocused() { bool MessageView::IsCloseButtonFocused() {
......
...@@ -7,50 +7,51 @@ ...@@ -7,50 +7,51 @@
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/shadow_value.h"
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace views { namespace views {
ShadowBorder::ShadowBorder(int blur, namespace {
SkColor color,
int vertical_offset, gfx::Insets GetInsetsFromShadowValue(const gfx::ShadowValue& shadow) {
int horizontal_offset) std::vector<gfx::ShadowValue> shadows;
shadows.push_back(shadow);
return -gfx::ShadowValue::GetMargin(shadows);
}
} // namespace
ShadowBorder::ShadowBorder(const gfx::ShadowValue& shadow)
: views::Border(), : views::Border(),
blur_(blur), shadow_value_(shadow),
color_(color), insets_(GetInsetsFromShadowValue(shadow)) {
vertical_offset_(vertical_offset), }
horizontal_offset_(horizontal_offset) {}
ShadowBorder::~ShadowBorder() {} ShadowBorder::~ShadowBorder() {
}
// TODO(sidharthms): Re-painting a shadow looper on every paint call may yield // TODO(sidharthms): Re-painting a shadow looper on every paint call may yield
// poor performance. Ideally we should be caching the border to bitmaps. // poor performance. Ideally we should be caching the border to bitmaps.
void ShadowBorder::Paint(const views::View& view, gfx::Canvas* canvas) { void ShadowBorder::Paint(const views::View& view, gfx::Canvas* canvas) {
SkPaint paint; SkPaint paint;
std::vector<gfx::ShadowValue> shadows; std::vector<gfx::ShadowValue> shadows;
shadows.push_back(gfx::ShadowValue(gfx::Point(), blur_, color_)); shadows.push_back(shadow_value_);
skia::RefPtr<SkDrawLooper> looper = gfx::CreateShadowDrawLooper(shadows); skia::RefPtr<SkDrawLooper> looper = gfx::CreateShadowDrawLooper(shadows);
paint.setLooper(looper.get()); paint.setLooper(looper.get());
paint.setColor(SK_ColorTRANSPARENT); paint.setColor(SK_ColorTRANSPARENT);
paint.setStrokeJoin(SkPaint::kRound_Join); paint.setStrokeJoin(SkPaint::kRound_Join);
gfx::Rect bounds(view.size()); gfx::Rect bounds(view.size());
// TODO(pkasting): This isn't right if one of the offsets is larger than bounds.Inset(-gfx::ShadowValue::GetMargin(shadows));
// (blur_ / 2).
bounds.Inset(gfx::Insets(blur_ / 2, blur_ / 2, blur_ / 2, blur_ / 2));
canvas->DrawRect(bounds, paint); canvas->DrawRect(bounds, paint);
} }
gfx::Insets ShadowBorder::GetInsets() const { gfx::Insets ShadowBorder::GetInsets() const {
return gfx::Insets(blur_ / 2 - vertical_offset_, return insets_;
blur_ / 2 - horizontal_offset_,
blur_ / 2 + vertical_offset_,
blur_ / 2 + horizontal_offset_);
} }
gfx::Size ShadowBorder::GetMinimumSize() const { gfx::Size ShadowBorder::GetMinimumSize() const {
return gfx::Size(blur_, blur_); return gfx::Size(shadow_value_.blur(), shadow_value_.blur());
} }
} // namespace views } // namespace views
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define UI_VIEWS_SHADOW_BORDER_H_ #define UI_VIEWS_SHADOW_BORDER_H_
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/shadow_value.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
...@@ -14,10 +15,7 @@ namespace views { ...@@ -14,10 +15,7 @@ namespace views {
// Creates a css box-shadow like border which fades into SK_ColorTRANSPARENT. // Creates a css box-shadow like border which fades into SK_ColorTRANSPARENT.
class VIEWS_EXPORT ShadowBorder : public views::Border { class VIEWS_EXPORT ShadowBorder : public views::Border {
public: public:
ShadowBorder(int blur, explicit ShadowBorder(const gfx::ShadowValue& shadow);
SkColor color,
int vertical_offset,
int horizontal_offset);
~ShadowBorder() override; ~ShadowBorder() override;
protected: protected:
...@@ -27,18 +25,11 @@ class VIEWS_EXPORT ShadowBorder : public views::Border { ...@@ -27,18 +25,11 @@ class VIEWS_EXPORT ShadowBorder : public views::Border {
gfx::Size GetMinimumSize() const override; gfx::Size GetMinimumSize() const override;
private: private:
// Blur amount of the shadow in pixels. For details on how blur is defined see // The shadow value to use for this border.
// comments for blur_ in class ShadowValue. const gfx::ShadowValue shadow_value_;
const int blur_;
// Shadow color. // The insets of this border.
const SkColor color_; const gfx::Insets insets_;
// Number of pixels to shift shadow to bottom.
const int vertical_offset_;
// Number of pixels to shift shadow to right.
const int horizontal_offset_;
DISALLOW_COPY_AND_ASSIGN(ShadowBorder); DISALLOW_COPY_AND_ASSIGN(ShadowBorder);
}; };
......
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