summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/autocomplete/autocomplete_edit_view_win.cc')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.cc82
1 files changed, 35 insertions, 47 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
index 6ead1fe..5a0632f 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
@@ -28,7 +28,6 @@
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/autocomplete/autocomplete_accessibility.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
-#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/command_updater.h"
@@ -387,10 +386,10 @@ AutocompleteEditViewWin::AutocompleteEditViewWin(
Profile* profile,
CommandUpdater* command_updater,
bool popup_window_mode,
- const BubblePositioner* bubble_positioner)
+ const views::View* location_bar)
: model_(new AutocompleteEditModel(this, controller, profile)),
- popup_view_(AutocompletePopupView::CreatePopupView(
- font, this, model_.get(), profile, bubble_positioner)),
+ popup_view_(new AutocompletePopupContentsView(font, this, model_.get(),
+ profile, location_bar)),
controller_(controller),
parent_view_(parent_view),
toolbar_model_(toolbar_model),
@@ -407,8 +406,9 @@ AutocompleteEditViewWin::AutocompleteEditViewWin(
in_drag_(false),
initiated_drag_(false),
drop_highlight_position_(-1),
- background_color_(0),
- scheme_security_level_(ToolbarModel::NORMAL),
+ background_color_(skia::SkColorToCOLORREF(LocationBarView::GetColor(
+ ToolbarModel::NONE, LocationBarView::BACKGROUND))),
+ security_level_(ToolbarModel::NONE),
text_object_model_(NULL) {
// Dummy call to a function exported by riched20.dll to ensure it sets up an
// import dependency on the dll.
@@ -459,6 +459,8 @@ AutocompleteEditViewWin::AutocompleteEditViewWin(
cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel;
SetDefaultCharFormat(cf);
+ SetBackgroundColor(background_color_);
+
// By default RichEdit has a drop target. Revoke it so that we can install our
// own. Revoke takes care of deleting the existing one.
RevokeDragDrop(m_hWnd);
@@ -508,30 +510,21 @@ void AutocompleteEditViewWin::Update(
model_->UpdatePermanentText(toolbar_model_->GetText());
const ToolbarModel::SecurityLevel security_level =
- toolbar_model_->GetSchemeSecurityLevel();
- const COLORREF background_color =
- skia::SkColorToCOLORREF(LocationBarView::GetColor(
- security_level == ToolbarModel::SECURE, LocationBarView::BACKGROUND));
- const bool changed_security_level =
- (security_level != scheme_security_level_);
+ toolbar_model_->GetSecurityLevel();
+ const bool changed_security_level = (security_level != security_level_);
// Bail early when no visible state will actually change (prevents an
// unnecessary ScopedFreeze, and thus UpdateWindow()).
- if ((background_color == background_color_) && !changed_security_level &&
- !visibly_changed_permanent_text && !tab_for_state_restoring)
+ if (!changed_security_level && !visibly_changed_permanent_text &&
+ !tab_for_state_restoring)
return;
- // Update our local state as desired. We set scheme_security_level_ here so
- // it will already be correct before we get to any RevertAll()s below and use
- // it.
- ScopedFreeze freeze(this, GetTextObjectModel());
- if (background_color_ != background_color) {
- background_color_ = background_color;
- SetBackgroundColor(background_color_);
- }
- scheme_security_level_ = security_level;
+ // Update our local state as desired. We set security_level_ here so it will
+ // already be correct before we get to any RevertAll()s below and use it.
+ security_level_ = security_level;
// When we're switching to a new tab, restore its state, if any.
+ ScopedFreeze freeze(this, GetTextObjectModel());
if (tab_for_state_restoring) {
// Make sure we reset our own state first. The new tab may not have any
// saved state, or it may not have had input in progress, in which case we
@@ -605,6 +598,16 @@ std::wstring AutocompleteEditViewWin::GetText() const {
return str;
}
+bool AutocompleteEditViewWin::IsEditingOrEmpty() const {
+ return model_->user_input_in_progress() || (GetTextLength() == 0);
+}
+
+int AutocompleteEditViewWin::GetIcon() const {
+ return IsEditingOrEmpty() ?
+ AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) :
+ toolbar_model_->GetIcon();
+}
+
void AutocompleteEditViewWin::SetUserText(const std::wstring& text,
const std::wstring& display_text,
bool update_popup) {
@@ -1369,15 +1372,6 @@ void AutocompleteEditViewWin::OnKillFocus(HWND focus_wnd) {
ScopedFreeze freeze(this, GetTextObjectModel());
DefWindowProc(WM_KILLFOCUS, reinterpret_cast<WPARAM>(focus_wnd), 0);
- // Hide the "Type to search" hint if necessary. We do this after calling
- // DefWindowProc() because processing the resulting IME messages may notify
- // the controller that input is in progress, which could cause the visible
- // hints to change. (I don't know if there's a real scenario where they
- // actually do change, but this is safest.)
- if (model_->show_search_hint() ||
- (model_->is_keyword_hint() && !model_->keyword().empty()))
- controller_->OnChanged();
-
// Cancel any user selection and scroll the text back to the beginning of the
// URL. We have to do this after calling DefWindowProc() because otherwise
// an in-progress IME composition will be completed at the new caret position,
@@ -1687,12 +1681,6 @@ void AutocompleteEditViewWin::OnSetFocus(HWND focus_wnd) {
model_->OnSetFocus(GetKeyState(VK_CONTROL) < 0);
- // Notify controller if it needs to show hint UI of some kind.
- ScopedFreeze freeze(this, GetTextObjectModel());
- if (model_->show_search_hint() ||
- (model_->is_keyword_hint() && !model_->keyword().empty()))
- controller_->OnChanged();
-
// Restore saved selection if available.
if (saved_selection_for_focus_change_.cpMin != -1) {
SetSelectionRange(saved_selection_for_focus_change_);
@@ -2060,11 +2048,11 @@ void AutocompleteEditViewWin::EmphasizeURLComponents() {
// Set the baseline emphasis.
CHARFORMAT cf = {0};
cf.dwMask = CFM_COLOR;
- const bool is_secure = (scheme_security_level_ == ToolbarModel::SECURE);
// If we're going to emphasize parts of the text, then the baseline state
// should be "de-emphasized". If not, then everything should be rendered in
// the standard text color.
- cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor(is_secure,
+ cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor(
+ security_level_,
emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT));
// NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets the
// format that will get applied to text added in the future, not to text
@@ -2075,7 +2063,7 @@ void AutocompleteEditViewWin::EmphasizeURLComponents() {
if (emphasize) {
// We've found a host name, give it more emphasis.
cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor(
- is_secure, LocationBarView::TEXT));
+ security_level_, LocationBarView::TEXT));
SetSelection(host.begin, host.end());
SetSelectionCharFormat(cf);
}
@@ -2083,13 +2071,13 @@ void AutocompleteEditViewWin::EmphasizeURLComponents() {
// Emphasize the scheme for security UI display purposes (if necessary).
insecure_scheme_component_.reset();
if (!model_->user_input_in_progress() && scheme.is_nonempty() &&
- (scheme_security_level_ != ToolbarModel::NORMAL)) {
- if (!is_secure) {
+ (security_level_ != ToolbarModel::NONE)) {
+ if (security_level_ == ToolbarModel::SECURITY_ERROR) {
insecure_scheme_component_.begin = scheme.begin;
insecure_scheme_component_.len = scheme.len;
}
cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor(
- is_secure, LocationBarView::SECURITY_TEXT));
+ security_level_, LocationBarView::SECURITY_TEXT));
SetSelection(scheme.begin, scheme.end());
SetSelectionCharFormat(cf);
}
@@ -2183,8 +2171,8 @@ void AutocompleteEditViewWin::DrawSlashForInsecureScheme(
canvas.save();
if (selection_rect.isEmpty() ||
canvas.clipRect(selection_rect, SkRegion::kDifference_Op)) {
- paint.setColor(LocationBarView::GetColor(false,
- LocationBarView::SCHEME_STRIKEOUT));
+ paint.setColor(LocationBarView::GetColor(security_level_,
+ LocationBarView::SECURITY_TEXT));
canvas.drawLine(start_point.fX, start_point.fY,
end_point.fX, end_point.fY, paint);
}
@@ -2192,7 +2180,7 @@ void AutocompleteEditViewWin::DrawSlashForInsecureScheme(
// Draw the selected portion of the stroke.
if (!selection_rect.isEmpty() && canvas.clipRect(selection_rect)) {
- paint.setColor(LocationBarView::GetColor(false,
+ paint.setColor(LocationBarView::GetColor(security_level_,
LocationBarView::SELECTED_TEXT));
canvas.drawLine(start_point.fX, start_point.fY,
end_point.fX, end_point.fY, paint);