#include "ui/views/controls/combobox/combobox_util.h"
#include <memory>
#include "cc/paint/paint_flags.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkPathBuilder.h"
#include "ui/base/ui_base_features.h"
#include "ui/color/color_id.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_host.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/layout/layout_provider.h"
#include "ui/views/style/typography.h"
#include "ui/views/style/typography_provider.h"
namespace views {
int GetComboboxArrowContainerWidthAndMargins() {
return GetComboboxArrowContainerWidth() +
LayoutProvider::Get()->GetDistanceMetric(
DISTANCE_TEXTFIELD_HORIZONTAL_TEXT_PADDING);
}
int GetComboboxArrowContainerWidth() {
return ComboboxArrowSize().width() + kComboboxArrowPaddingWidth * 2;
}
void PaintComboboxArrow(SkColor color,
const gfx::Rect& bounds,
gfx::Canvas* canvas) {
float dsf = canvas->UndoDeviceScaleFactor();
SkScalar x = std::ceil(bounds.x() * dsf);
SkScalar y = std::ceil(bounds.y() * dsf);
SkScalar height = std::floor(bounds.height() * dsf);
SkPathBuilder path;
constexpr SkScalar kEpsilon = 0.0001f;
path.moveTo(x - kEpsilon, y);
path.rLineTo(height, height);
path.rLineTo(2 * kEpsilon, 0);
path.rLineTo(height, -height);
path.close();
cc::PaintFlags flags;
flags.setColor(color);
flags.setAntiAlias(true);
canvas->DrawPath(path.detach(), flags);
}
void ConfigureComboboxButtonInkDrop(Button* host_view) {
constexpr float kOpaque = 1;
InkDrop::Get(host_view)->SetMode(views::InkDropHost::InkDropMode::ON);
host_view->SetHasInkDropActionOnClick(true);
InkDrop::UseInkDropForFloodFillRipple(InkDrop::Get(host_view),
true);
InkDrop::Get(host_view)->SetHighlightOpacity(kOpaque);
views::InkDrop::Get(host_view)->SetBaseColorCallback(base::BindRepeating(
[](Button* host) {
return color_utils::DeriveDefaultIconColor(
host->GetColorProvider()->GetColor(
ui::kColorComboboxInkDropHovered));
},
host_view));
InkDrop::Get(host_view)->SetCreateRippleCallback(base::BindRepeating(
[](Button* host, float opacity) -> std::unique_ptr<views::InkDropRipple> {
return std::make_unique<views::FloodFillInkDropRipple>(
InkDrop::Get(host), host->size(),
InkDrop::Get(host)->GetInkDropCenterBasedOnLastEvent(),
host->GetColorProvider()->GetColor(ui::kColorComboboxInkDropRipple),
opacity);
},
host_view, kOpaque));
}
}