// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/system/accessibility/switch_access_menu_button.h"

#include "ash/style/ash_color_provider.h"
#include "base/bind.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/mojom/ax_node_data.mojom-shared.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icon_types.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/style/typography.h"

namespace ash {

namespace {
constexpr int kButtonBottomPaddingDefaultDip = 8;
constexpr int kButtonBottomPaddingSmallDip = 1;
constexpr int kButtonTopPaddingDip = 16;
constexpr int kIconSizeDip = 20;
constexpr int kLabelMinSidePaddingDip = 8;
constexpr int kLabelMaxWidthDip =
    SwitchAccessMenuButton::kWidthDip - 2 * kLabelMinSidePaddingDip;
constexpr int kLabelTopPaddingDefaultDip = 16;
constexpr int kLabelTopPaddingSmallDip = 8;
constexpr int kTextLineHeightDip = 20;
}  // namespace

SwitchAccessMenuButton::SwitchAccessMenuButton(std::string action_name,
                                               const gfx::VectorIcon& icon,
                                               int label_text_id)
    : views::Button(
          base::BindRepeating(&SwitchAccessMenuButton::OnButtonPressed,
                              base::Unretained(this))),
      action_name_(action_name) {
  SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor(
      AshColorProvider::ContentLayerType::kIconColorPrimary);
  SkColor label_color = AshColorProvider::Get()->GetContentLayerColor(
      AshColorProvider::ContentLayerType::kTextColorPrimary);

  std::u16string label_text = l10n_util::GetStringUTF16(label_text_id);
  views::Builder<SwitchAccessMenuButton>(this)
      .SetFocusBehavior(views::View::FocusBehavior::ACCESSIBLE_ONLY)
      .AddChildren(
          {views::Builder<views::ImageView>()
               .CopyAddressTo(&image_view_)
               .SetImage(gfx::CreateVectorIcon(icon, kIconSizeDip, icon_color)),
           views::Builder<views::Label>()
               .CopyAddressTo(&label_)
               .SetText(label_text)
               .SetTextContext(views::style::CONTEXT_BUTTON)
               .SetAutoColorReadabilityEnabled(false)
               .SetEnabledColor(label_color)
               .SetMultiLine(true)
               .SetMaximumWidth(kLabelMaxWidthDip)})
      .BuildChildren();

  std::unique_ptr<views::BoxLayout> layout = std::make_unique<views::BoxLayout>(
      views::BoxLayout::Orientation::kVertical,
      gfx::Insets(kButtonTopPaddingDip, kLabelMinSidePaddingDip,
                  kButtonBottomPaddingDefaultDip, kLabelMinSidePaddingDip),
      kLabelTopPaddingDefaultDip);

  // The layout padding changes with the size of the text label.
  gfx::Size label_size = label_->CalculatePreferredSize();
  int left_padding_dip = (kWidthDip - label_size.width()) / 2;
  int right_padding_dip = kWidthDip - left_padding_dip - label_size.width();
  int bottom_padding_dip = kButtonBottomPaddingDefaultDip;
  if (label_size.height() > kTextLineHeightDip) {
    bottom_padding_dip = kButtonBottomPaddingSmallDip;
    layout->set_between_child_spacing(kLabelTopPaddingSmallDip);
  }
  layout->set_inside_border_insets(
      gfx::Insets(kButtonTopPaddingDip, left_padding_dip, bottom_padding_dip,
                  right_padding_dip));
  SetLayoutManager(std::move(layout));

  GetViewAccessibility().OverrideName(label_text);
  GetViewAccessibility().OverrideIsLeaf(true);
}

void SwitchAccessMenuButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
  views::Button::GetAccessibleNodeData(node_data);
  node_data->AddStringAttribute(ax::mojom::StringAttribute::kValue,
                                action_name_);
}

void SwitchAccessMenuButton::OnButtonPressed() {
  NotifyAccessibilityEvent(ax::mojom::Event::kClicked,
                           /*send_native_event=*/false);
}

BEGIN_METADATA(SwitchAccessMenuButton, views::Button)
END_METADATA

}  // namespace ash
