feat: customize border radius of Views (#42320)
* feat: add View#setBorderRadius test: initial setBorderRadius tests fix: robustly set border radius chore: add PAUSE_CAPTURE_TESTS for easier screencap dev feat: add view border radius support test: view border radius refactor: cleanup view code * maybe delay capture to fix tests? * refactor: retry screen captures in an attempt to fix flakiness * refactor: ScreenCapture constructor no longer async * increase screen capture timeout, feels a little short * refactor: move rounded rect util into chromium_src * skip some capture tests on mas
This commit is contained in:
parent
cbd11bb605
commit
778d3098a0
15 changed files with 261 additions and 90 deletions
|
@ -10,6 +10,7 @@
|
|||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "ash/style/rounded_rect_cutout_path_builder.h"
|
||||
#include "gin/data_object_builder.h"
|
||||
#include "gin/wrappable.h"
|
||||
#include "shell/browser/javascript_environment.h"
|
||||
|
@ -338,6 +339,38 @@ void View::SetBackgroundColor(std::optional<WrappedSkColor> color) {
|
|||
view_->SetBackground(color ? views::CreateSolidBackground(*color) : nullptr);
|
||||
}
|
||||
|
||||
void View::SetBorderRadius(int radius) {
|
||||
border_radius_ = radius;
|
||||
ApplyBorderRadius();
|
||||
}
|
||||
|
||||
void View::ApplyBorderRadius() {
|
||||
if (!border_radius_.has_value() || !view_)
|
||||
return;
|
||||
|
||||
auto size = view_->bounds().size();
|
||||
|
||||
// Restrict border radius to the constraints set in the path builder class.
|
||||
// If the constraints are exceeded, the builder will crash.
|
||||
int radius;
|
||||
{
|
||||
float r = border_radius_.value() * 1.f;
|
||||
r = std::min(r, size.width() / 2.f);
|
||||
r = std::min(r, size.height() / 2.f);
|
||||
r = std::max(r, 0.f);
|
||||
radius = std::floor(r);
|
||||
}
|
||||
|
||||
// RoundedRectCutoutPathBuilder has a minimum size of 32 x 32.
|
||||
if (radius > 0 && size.width() >= 32 && size.height() >= 32) {
|
||||
auto builder = ash::RoundedRectCutoutPathBuilder(gfx::SizeF(size));
|
||||
builder.CornerRadius(radius);
|
||||
view_->SetClipPath(builder.Build());
|
||||
} else {
|
||||
view_->SetClipPath(SkPath());
|
||||
}
|
||||
}
|
||||
|
||||
void View::SetVisible(bool visible) {
|
||||
if (!view_)
|
||||
return;
|
||||
|
@ -345,6 +378,7 @@ void View::SetVisible(bool visible) {
|
|||
}
|
||||
|
||||
void View::OnViewBoundsChanged(views::View* observed_view) {
|
||||
ApplyBorderRadius();
|
||||
Emit("bounds-changed");
|
||||
}
|
||||
|
||||
|
@ -393,6 +427,7 @@ void View::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("setBounds", &View::SetBounds)
|
||||
.SetMethod("getBounds", &View::GetBounds)
|
||||
.SetMethod("setBackgroundColor", &View::SetBackgroundColor)
|
||||
.SetMethod("setBorderRadius", &View::SetBorderRadius)
|
||||
.SetMethod("setLayout", &View::SetLayout)
|
||||
.SetMethod("setVisible", &View::SetVisible);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue