Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: ui/views/controls/button/md_text_button.cc

Issue 2514303004: WIP - mask a view's layer by its view coordinates
Patch Set: manual clip Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/button/md_text_button.cc
diff --git a/ui/views/controls/button/md_text_button.cc b/ui/views/controls/button/md_text_button.cc
index 9da1078f7692fe0cc322330f54828c6e15cb0066..217fad3cbe5a7ab474996555b0a840a3c6565a55 100644
--- a/ui/views/controls/button/md_text_button.cc
+++ b/ui/views/controls/button/md_text_button.cc
@@ -6,6 +6,8 @@
#include "base/i18n/case_conversion.h"
#include "ui/base/material_design/material_design_controller.h"
+#include "ui/compositor/paint_context.h"
+#include "ui/compositor/paint_recorder.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
@@ -28,6 +30,29 @@ namespace {
// Minimum size to reserve for the button contents.
const int kMinWidth = 48;
+class VisibleMaskLayerDelegate : public ui::LayerDelegate {
+ public:
+ explicit VisibleMaskLayerDelegate(views::View* view, const ui::Layer* layer)
+ : view_(view), layer_(layer) {}
+ ~VisibleMaskLayerDelegate() override {}
+
+ // ui::LayerDelegate:
+ void OnPaintLayer(const ui::PaintContext& context) override {
+ ui::PaintRecorder recorder(context, layer_->size());
+ gfx::Rect bounds = view_->GetVisibleBounds();
+ recorder.canvas()->FillRect(bounds, SK_ColorBLACK);
+ }
+
+ void OnDelegatedFrameDamage(
+ const gfx::Rect& damage_rect_in_dip) override {}
+ void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
+
+ private:
+views::View* view_;
+ const ui::Layer* const layer_;
+ DISALLOW_COPY_AND_ASSIGN(VisibleMaskLayerDelegate);
+};
+
LabelButton* CreateButton(ButtonListener* listener,
const base::string16& text,
bool md) {
@@ -103,6 +128,22 @@ void MdTextButton::OnPaintBackground(gfx::Canvas* canvas) {
}
}
+bool MdTextButton::GetNeedsNotificationWhenVisibleBoundsChange() const {
+ return true;
+}
+
+void MdTextButton::OnVisibleBoundsChanged() {
+ gfx::Rect visible_bounds = GetVisibleBounds();
+ if (last_visible_bounds_ != visible_bounds)
+ SchedulePaint();
+ last_visible_bounds_ = visible_bounds;
+}
+
+void MdTextButton::OnLayerBoundsChanged(const gfx::Rect& old_bounds) {
+ LabelButton::OnLayerBoundsChanged(old_bounds);
+ // mask_layer_.SetBounds(layer()->bounds());
+}
+
void MdTextButton::OnFocus() {
LabelButton::OnFocus();
FocusRing::Install(this);
@@ -206,6 +247,12 @@ MdTextButton::MdTextButton(ButtonListener* listener)
// for fractional DSF).
SetPaintToLayer(true);
layer()->SetFillsBoundsOpaquely(false);
+/*
+ mask_layer_.SetFillsBoundsOpaquely(false);
+ mask_layer_delegate_.reset(new VisibleMaskLayerDelegate(this, &mask_layer_));
+ mask_layer_.set_delegate(mask_layer_delegate_.get());
+ layer()->SetMaskLayer(&mask_layer_);
+*/
}
void MdTextButton::UpdatePadding() {
« no previous file with comments | « ui/views/controls/button/md_text_button.h ('k') | ui/views/view.cc » ('j') | ui/views/view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698