#include "ui/views/accessibility/views_utilities_aura.h"
#include <algorithm>
#include "base/i18n/break_iterator.h"
#include "base/i18n/rtl.h"
#include "ui/aura/window.h"
#include "ui/gfx/decorated_text.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/range/range.h"
#include "ui/gfx/render_text.h"
#include "ui/gfx/selection_model.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/window_util.h"
namespace views {
#if BUILDFLAG(SUPPORTS_AX_TEXT_OFFSETS)
WordBoundaries::WordBoundaries() = default;
WordBoundaries::WordBoundaries(const WordBoundaries& other) = default;
WordBoundaries::~WordBoundaries() = default;
#endif
aura::Window* GetWindowParentIncludingTransient(aura::Window* window) { … }
#if BUILDFLAG(SUPPORTS_AX_TEXT_OFFSETS)
WordBoundaries ComputeWordBoundaries(const std::u16string& text) {
WordBoundaries boundaries;
base::i18n::BreakIterator iter(text, base::i18n::BreakIterator::BREAK_WORD);
if (!iter.Init()) {
return boundaries;
}
while (iter.Advance()) {
if (iter.IsWord()) {
boundaries.starts.push_back(static_cast<int32_t>(iter.prev()));
boundaries.ends.push_back(static_cast<int32_t>(iter.pos()));
}
}
return boundaries;
}
std::vector<int32_t> ComputeTextOffsets(gfx::RenderText* render_text) {
std::vector<int32_t> offsets;
if (!render_text || render_text->multiline() ||
render_text->elide_behavior() == gfx::ELIDE_MIDDLE ||
render_text->elide_behavior() == gfx::ELIDE_HEAD ||
render_text->elide_behavior() == gfx::ELIDE_EMAIL) {
return offsets;
}
size_t begin_position = 0;
int last_x = 0;
int offset = render_text->GetUpdatedDisplayOffset().x();
while (begin_position < render_text->text().length()) {
size_t end_position = render_text->IndexOfAdjacentGrapheme(
begin_position, gfx::CURSOR_FORWARD);
gfx::Range range(begin_position, end_position);
gfx::Rect bounds;
gfx::DecoratedText decorated_text;
render_text->GetLookupDataForRange(range, &decorated_text, &bounds);
if (bounds.IsEmpty()) {
offsets.push_back(last_x);
} else {
offsets.push_back(bounds.x() - offset);
last_x = bounds.right() - offset;
}
begin_position = end_position;
}
if (offsets.empty()) {
return offsets;
}
offsets.push_back(last_x);
return offsets;
}
#endif
}