#include "ui/views/controls/label.h"
#include <stddef.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <utility>
#include "base/i18n/rtl.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/platform/ax_platform.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/default_style.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/color/color_provider.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/text_elider.h"
#include "ui/gfx/text_utils.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/accessibility/views_utilities_aura.h"
#include "ui/views/background.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/selection_controller.h"
#include "ui/views/style/typography_provider.h"
namespace {
enum LabelPropertyKey { … };
bool IsOpaque(SkColor color) { … }
}
namespace views {
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(…)
Label::Label() : … { … }
Label::Label(const std::u16string& text)
: … { … }
Label::Label(const std::u16string& text,
int text_context,
int text_style,
gfx::DirectionalityMode directionality_mode)
: … { … }
Label::Label(const std::u16string& text, const CustomFont& font)
: … { … }
Label::~Label() = default;
const gfx::FontList& Label::GetDefaultFontList() { … }
void Label::SetFontList(const gfx::FontList& font_list) { … }
const std::u16string& Label::GetText() const { … }
void Label::SetText(const std::u16string& new_text) { … }
void Label::AdjustAccessibleName(std::u16string& new_name,
ax::mojom::NameFrom& name_from) { … }
int Label::GetTextContext() const { … }
void Label::SetTextContext(int text_context) { … }
int Label::GetTextStyle() const { … }
void Label::SetTextStyle(int style) { … }
void Label::ApplyBaselineTextStyle() { … }
void Label::SetTextStyleRange(int style, const gfx::Range& range) { … }
bool Label::GetAutoColorReadabilityEnabled() const { … }
void Label::SetAutoColorReadabilityEnabled(
bool auto_color_readability_enabled) { … }
SkColor Label::GetEnabledColor() const { … }
void Label::SetEnabledColor(SkColor color) { … }
std::optional<ui::ColorId> Label::GetEnabledColorId() const { … }
void Label::SetEnabledColorId(std::optional<ui::ColorId> enabled_color_id) { … }
SkColor Label::GetBackgroundColor() const { … }
void Label::SetBackgroundColor(SkColor color) { … }
void Label::SetBackgroundColorId(
std::optional<ui::ColorId> background_color_id) { … }
SkColor Label::GetSelectionTextColor() const { … }
void Label::SetSelectionTextColor(SkColor color) { … }
SkColor Label::GetSelectionBackgroundColor() const { … }
void Label::SetSelectionBackgroundColor(SkColor color) { … }
const gfx::ShadowValues& Label::GetShadows() const { … }
void Label::SetShadows(const gfx::ShadowValues& shadows) { … }
bool Label::GetSubpixelRenderingEnabled() const { … }
void Label::SetSubpixelRenderingEnabled(bool subpixel_rendering_enabled) { … }
bool Label::GetSkipSubpixelRenderingOpacityCheck() const { … }
void Label::SetSkipSubpixelRenderingOpacityCheck(
bool skip_subpixel_rendering_opacity_check) { … }
gfx::HorizontalAlignment Label::GetHorizontalAlignment() const { … }
void Label::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) { … }
gfx::VerticalAlignment Label::GetVerticalAlignment() const { … }
void Label::SetVerticalAlignment(gfx::VerticalAlignment alignment) { … }
int Label::GetLineHeight() const { … }
void Label::SetLineHeight(int line_height) { … }
bool Label::GetMultiLine() const { … }
void Label::SetMultiLine(bool multi_line) { … }
size_t Label::GetMaxLines() const { … }
void Label::SetMaxLines(size_t max_lines) { … }
bool Label::GetObscured() const { … }
void Label::SetObscured(bool obscured) { … }
bool Label::IsDisplayTextClipped() const { … }
bool Label::IsDisplayTextTruncated() const { … }
bool Label::GetAllowCharacterBreak() const { … }
void Label::SetAllowCharacterBreak(bool allow_character_break) { … }
size_t Label::GetTextIndexOfLine(size_t line) const { … }
void Label::SetTruncateLength(size_t truncate_length) { … }
gfx::ElideBehavior Label::GetElideBehavior() const { … }
void Label::SetElideBehavior(gfx::ElideBehavior elide_behavior) { … }
std::u16string Label::GetTooltipText() const { … }
void Label::SetTooltipText(const std::u16string& tooltip_text) { … }
bool Label::GetHandlesTooltips() const { … }
void Label::SetHandlesTooltips(bool enabled) { … }
int Label::GetFixedWidth() const { … }
void Label::SizeToFit(int fixed_width) { … }
int Label::GetMaximumWidth() const { … }
void Label::SetMaximumWidth(int max_width) { … }
void Label::SetMaximumWidthSingleLine(int max_width) { … }
bool Label::GetCollapseWhenHidden() const { … }
void Label::SetCollapseWhenHidden(bool value) { … }
size_t Label::GetRequiredLines() const { … }
const std::u16string Label::GetDisplayTextForTesting() const { … }
base::i18n::TextDirection Label::GetTextDirectionForTesting() { … }
bool Label::IsSelectionSupported() const { … }
bool Label::GetSelectable() const { … }
bool Label::SetSelectable(bool value) { … }
bool Label::HasSelection() const { … }
bool Label::HasFullSelection() const { … }
void Label::SelectAll() { … }
void Label::ClearSelection() { … }
void Label::SelectRange(const gfx::Range& range) { … }
std::vector<gfx::Rect> Label::GetSubstringBounds(const gfx::Range& range) { … }
base::CallbackListSubscription Label::AddTextChangedCallback(
views::PropertyChangedCallback callback) { … }
base::CallbackListSubscription Label::AddTextContextChangedCallback(
views::PropertyChangedCallback callback) { … }
int Label::GetBaseline() const { … }
gfx::Size Label::CalculatePreferredSize(
const SizeBounds& available_size) const { … }
gfx::Size Label::GetMinimumSize() const { … }
int Label::GetLabelHeightForWidth(int w) const { … }
View* Label::GetTooltipHandlerForPoint(const gfx::Point& point) { … }
bool Label::GetCanProcessEventsWithinSubtree() const { … }
WordLookupClient* Label::GetWordLookupClient() { … }
std::u16string Label::GetTooltipText(const gfx::Point& p) const { … }
std::unique_ptr<gfx::RenderText> Label::CreateRenderText() const { … }
gfx::Rect Label::GetTextBounds() const { … }
int Label::GetFontListY() const { … }
void Label::PaintText(gfx::Canvas* canvas) { … }
void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { … }
void Label::OnPaint(gfx::Canvas* canvas) { … }
void Label::OnThemeChanged() { … }
ui::Cursor Label::GetCursor(const ui::MouseEvent& event) { … }
void Label::OnFocus() { … }
void Label::OnBlur() { … }
bool Label::OnMousePressed(const ui::MouseEvent& event) { … }
bool Label::OnMouseDragged(const ui::MouseEvent& event) { … }
void Label::OnMouseReleased(const ui::MouseEvent& event) { … }
void Label::OnMouseCaptureLost() { … }
bool Label::OnKeyPressed(const ui::KeyEvent& event) { … }
bool Label::AcceleratorPressed(const ui::Accelerator& accelerator) { … }
bool Label::CanHandleAccelerators() const { … }
void Label::GetAccessibleNodeData(ui::AXNodeData* node_data) { … }
#if BUILDFLAG(SUPPORTS_AX_TEXT_OFFSETS)
bool Label::RefreshAccessibleTextOffsets() {
MaybeBuildDisplayText();
if (!display_text_ || display_text_->multiline()) {
return false;
}
GetViewAccessibility().SetCharacterOffsets(
ComputeTextOffsets(display_text_.get()));
WordBoundaries boundaries = ComputeWordBoundaries(GetText());
GetViewAccessibility().SetWordStarts(boundaries.starts);
GetViewAccessibility().SetWordEnds(boundaries.ends);
return true;
}
#endif
void Label::OnDeviceScaleFactorChanged(float old_device_scale_factor,
float new_device_scale_factor) { … }
void Label::VisibilityChanged(View* starting_from, bool is_visible) { … }
void Label::ShowContextMenuForViewImpl(View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) { … }
bool Label::GetWordLookupDataAtPoint(const gfx::Point& point,
gfx::DecoratedText* decorated_word,
gfx::Rect* rect) { … }
bool Label::GetWordLookupDataFromSelection(gfx::DecoratedText* decorated_text,
gfx::Rect* rect) { … }
gfx::RenderText* Label::GetRenderTextForSelectionController() { … }
bool Label::IsReadOnly() const { … }
bool Label::SupportsDrag() const { … }
bool Label::HasTextBeingDragged() const { … }
void Label::SetTextBeingDragged(bool value) { … }
int Label::GetViewHeight() const { … }
int Label::GetViewWidth() const { … }
int Label::GetDragSelectionDelay() const { … }
void Label::OnBeforePointerAction() { … }
void Label::OnAfterPointerAction(bool text_changed, bool selection_changed) { … }
bool Label::PasteSelectionClipboard() { … }
void Label::UpdateSelectionClipboard() { … }
bool Label::IsCommandIdChecked(int command_id) const { … }
bool Label::IsCommandIdEnabled(int command_id) const { … }
void Label::ExecuteCommand(int command_id, int event_flags) { … }
bool Label::GetAcceleratorForCommandId(int command_id,
ui::Accelerator* accelerator) const { … }
const gfx::RenderText* Label::GetRenderTextForSelectionController() const { … }
void Label::Init(const std::u16string& text,
const gfx::FontList& font_list,
gfx::DirectionalityMode directionality_mode) { … }
void Label::MaybeBuildDisplayText() const { … }
gfx::Size Label::GetTextSize() const { … }
gfx::Size Label::GetBoundedTextSize(const SizeBounds& available_size) const { … }
SkColor Label::GetForegroundColor(SkColor foreground,
SkColor background) const { … }
void Label::RecalculateColors() { … }
void Label::ApplyTextColors() const { … }
void Label::UpdateColorsFromTheme() { … }
bool Label::ShouldShowDefaultTooltip() const { … }
void Label::ClearDisplayText() { … }
std::u16string Label::GetSelectedText() const { … }
void Label::CopyToClipboard() { … }
void Label::BuildContextMenuContents() { … }
void Label::UpdateFullTextElideBehavior() { … }
BEGIN_METADATA(…)
}