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

Unified Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

Issue 7265011: RenderText API Outline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add TODO comments, revise cursor movement API, etc. Created 9 years, 5 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
Index: chrome/browser/ui/views/omnibox/omnibox_view_views.cc
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index 08b65b9e9dcf1d883d931ad3a59b9ca177a40aa2..957571197e1d98c2abb6ef9e822da28d7c389806 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -27,8 +27,8 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font.h"
+#include "ui/gfx/render_text.h"
#include "views/border.h"
-#include "views/controls/textfield/text_style.h"
#include "views/controls/textfield/textfield.h"
#include "views/layout/fill_layout.h"
@@ -135,11 +135,7 @@ OmniboxViewViews::OmniboxViewViews(AutocompleteEditController* controller,
popup_window_mode_(popup_window_mode),
security_level_(ToolbarModel::NONE),
ime_composing_before_change_(false),
- delete_at_end_pressed_(false),
- faded_text_style_(NULL),
- normal_text_style_(NULL),
- security_error_scheme_style_(NULL),
- secure_scheme_style_(NULL) {
+ delete_at_end_pressed_(false) {
set_border(views::Border::CreateEmptyBorder(kAutocompleteVerticalMargin, 0,
kAutocompleteVerticalMargin, 0));
}
@@ -623,7 +619,6 @@ size_t OmniboxViewViews::GetTextLength() const {
}
void OmniboxViewViews::EmphasizeURLComponents() {
- InitTextStyles();
// See whether the contents are a URL with a non-empty host portion, which we
// should emphasize. To check for a URL, rather than using the type returned
// by Parse(), ask the model, which will check the desired page transition for
@@ -635,33 +630,37 @@ void OmniboxViewViews::EmphasizeURLComponents() {
AutocompleteInput::ParseForEmphasizeComponents(
text, model_->GetDesiredTLD(), &scheme, &host);
const bool emphasize = model_->CurrentTextIsURL() && (host.len > 0);
-
- textfield_->ClearAllTextStyles();
+ gfx::StyleRange base_style;
+ base_style.foreground = emphasize ? kFadedTextColor : kNormalTextColor;
+ base_style.range = ui::Range(0, text.length());
+ textfield_->ApplyStyleRange(base_style);
if (emphasize) {
oshima 2011/07/23 09:51:12 While I understand what it's doing, it is now a bi
msw 2011/07/25 05:09:54 Done.
- textfield_->ApplyTextStyle(faded_text_style_, ui::Range(0, text.length()));
- textfield_->ApplyTextStyle(normal_text_style_,
- ui::Range(host.begin, host.end()));
- } else {
- textfield_->ApplyTextStyle(normal_text_style_, ui::Range(0, text.length()));
+ gfx::StyleRange host_style;
+ host_style.foreground = kNormalTextColor;
+ host_style.range = ui::Range(host.begin, host.end());
+ textfield_->ApplyStyleRange(host_style);
}
// Emphasize the scheme for security UI display purposes (if necessary).
if (!model_->user_input_in_progress() && scheme.is_nonempty() &&
(security_level_ != ToolbarModel::NONE)) {
- ui::Range scheme_range(scheme.begin, scheme.end());
+ gfx::StyleRange scheme_style;
+ scheme_style.range = ui::Range(scheme.begin, scheme.end());
switch (security_level_) {
case ToolbarModel::SECURITY_ERROR:
- textfield_->ApplyTextStyle(security_error_scheme_style_, scheme_range);
+ scheme_style.foreground = kSecurityErrorSchemeColor;
+ scheme_style.strike = true;
break;
case ToolbarModel::SECURITY_WARNING:
- textfield_->ApplyTextStyle(faded_text_style_, scheme_range);
+ scheme_style.foreground = kFadedTextColor;
break;
case ToolbarModel::EV_SECURE:
case ToolbarModel::SECURE:
- textfield_->ApplyTextStyle(secure_scheme_style_, scheme_range);
+ scheme_style.foreground = kSecureSchemeColor;
break;
default:
NOTREACHED() << "Unknown SecurityLevel:" << security_level_;
}
+ textfield_->ApplyStyleRange(scheme_style);
}
}
@@ -698,18 +697,3 @@ AutocompletePopupView* OmniboxViewViews::CreatePopupView(
return new AutocompleteContentsView(
gfx::Font(), this, model_.get(), profile, location_bar);
}
-
-void OmniboxViewViews::InitTextStyles() {
- if (faded_text_style_)
- return;
- faded_text_style_ = textfield_->CreateTextStyle();
- normal_text_style_ = textfield_->CreateTextStyle();
- security_error_scheme_style_ = textfield_->CreateTextStyle();
- secure_scheme_style_ = textfield_->CreateTextStyle();
-
- faded_text_style_->set_foreground(kFadedTextColor);
- normal_text_style_->set_foreground(kNormalTextColor);
- secure_scheme_style_->set_foreground(kSecureSchemeColor);
- security_error_scheme_style_->set_foreground(kSecurityErrorSchemeColor);
- security_error_scheme_style_->set_strike(true);
-}

Powered by Google App Engine
This is Rietveld 408576698