Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Unified Diff: ui/gfx/render_text_harfbuzz.cc

Issue 2348143003: MacViews: Implement Force Touch/Mac dictionary lookup for Textfields. (Closed)
Patch Set: Address nits. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/render_text_harfbuzz.h ('k') | ui/gfx/render_text_mac.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_harfbuzz.cc
diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc
index d0b3dd7200278cbaadb91c086ddda01ec5a6638b..e6964c5178b8303ae0437749fe83005fbb8d071d 100644
--- a/ui/gfx/render_text_harfbuzz.cc
+++ b/ui/gfx/render_text_harfbuzz.cc
@@ -23,6 +23,7 @@
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "ui/gfx/canvas.h"
+#include "ui/gfx/decorated_text.h"
#include "ui/gfx/font.h"
#include "ui/gfx/font_fallback.h"
#include "ui/gfx/font_render_params.h"
@@ -847,13 +848,9 @@ std::vector<RenderText::FontSpan> RenderTextHarfBuzz::GetFontSpansForTesting() {
internal::TextRunList* run_list = GetRunList();
std::vector<RenderText::FontSpan> spans;
for (auto* run : run_list->runs()) {
- SkString family_name;
- run->skia_face->getFamilyName(&family_name);
- Font font(family_name.c_str(), run->font_size);
spans.push_back(RenderText::FontSpan(
- font,
- Range(DisplayIndexToTextIndex(run->range.start()),
- DisplayIndexToTextIndex(run->range.end()))));
+ run->font, Range(DisplayIndexToTextIndex(run->range.start()),
+ DisplayIndexToTextIndex(run->range.end()))));
}
return spans;
@@ -1590,4 +1587,43 @@ const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const {
return const_cast<RenderTextHarfBuzz*>(this)->GetRunList();
}
+bool RenderTextHarfBuzz::GetDecoratedTextForRange(
+ const Range& range,
+ DecoratedText* decorated_text) {
+ if (obscured())
+ return false;
+
+ EnsureLayout();
+
+ decorated_text->attributes.clear();
+ decorated_text->text = GetTextFromRange(range);
+
+ const internal::TextRunList* run_list = GetRunList();
+ for (size_t i = 0; i < run_list->size(); i++) {
+ const internal::TextRunHarfBuzz& run = *run_list->runs()[i];
+
+ const Range intersection = range.Intersect(run.range);
+ DCHECK(!intersection.is_reversed());
+
+ if (!intersection.is_empty()) {
+ int style = Font::NORMAL;
+ if (run.italic)
+ style |= Font::ITALIC;
+ if (run.underline)
+ style |= Font::UNDERLINE;
+
+ // Get range relative to the decorated text.
+ DecoratedText::RangedAttribute attribute(
+ Range(intersection.start() - range.GetMin(),
+ intersection.end() - range.GetMin()),
+ run.font.Derive(0, style, run.weight));
+
+ attribute.strike = run.strike;
+ attribute.diagonal_strike = run.diagonal_strike;
+ decorated_text->attributes.push_back(attribute);
+ }
+ }
+ return true;
+}
+
} // namespace gfx
« no previous file with comments | « ui/gfx/render_text_harfbuzz.h ('k') | ui/gfx/render_text_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698