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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_win.cc

Issue 200009: Use system themes where possible in Omnibox, dropdown, and security info bubb... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h"
6 6
7 #include <locale> 7 #include <locale>
8 8
9 #include "app/gfx/canvas.h" 9 #include "app/gfx/canvas.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 306
307 AutocompleteEditViewWin::ScopedSuspendUndo::~ScopedSuspendUndo() { 307 AutocompleteEditViewWin::ScopedSuspendUndo::~ScopedSuspendUndo() {
308 // Resume Undo processing. 308 // Resume Undo processing.
309 if (text_object_model_) 309 if (text_object_model_)
310 text_object_model_->Undo(tomResume, NULL); 310 text_object_model_->Undo(tomResume, NULL);
311 } 311 }
312 312
313 /////////////////////////////////////////////////////////////////////////////// 313 ///////////////////////////////////////////////////////////////////////////////
314 // AutocompleteEditViewWin 314 // AutocompleteEditViewWin
315 315
316 // TODO (jcampan): these colors should be derived from the system colors to
317 // ensure they show properly. Bug #948807.
318 // Colors used to emphasize the scheme in the URL.
319
320 namespace { 316 namespace {
321 317
322 const COLORREF kSecureSchemeColor = RGB(0, 150, 20);
323 const COLORREF kInsecureSchemeColor = RGB(200, 0, 0);
324
325 // Colors used to strike-out the scheme when it is insecure.
326 const SkColor kSchemeStrikeoutColor = SkColorSetRGB(210, 0, 0);
327 const SkColor kSchemeSelectedStrikeoutColor =
328 SkColorSetRGB(255, 255, 255);
329
330 // These are used to hook the CRichEditCtrl's calls to BeginPaint() and 318 // These are used to hook the CRichEditCtrl's calls to BeginPaint() and
331 // EndPaint() and provide a memory DC instead. See OnPaint(). 319 // EndPaint() and provide a memory DC instead. See OnPaint().
332 HWND edit_hwnd = NULL; 320 HWND edit_hwnd = NULL;
333 PAINTSTRUCT paint_struct; 321 PAINTSTRUCT paint_struct;
334 322
335 // Intercepted method for BeginPaint(). Must use __stdcall convention. 323 // Intercepted method for BeginPaint(). Must use __stdcall convention.
336 HDC WINAPI BeginPaintIntercept(HWND hWnd, LPPAINTSTRUCT lpPaint) { 324 HDC WINAPI BeginPaintIntercept(HWND hWnd, LPPAINTSTRUCT lpPaint) {
337 if (!edit_hwnd || (hWnd != edit_hwnd)) 325 if (!edit_hwnd || (hWnd != edit_hwnd))
338 return ::BeginPaint(hWnd, lpPaint); 326 return ::BeginPaint(hWnd, lpPaint);
339 327
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 // rendered text. 446 // rendered text.
459 const int kTextBaseline = popup_window_mode_ ? 15 : 18; 447 const int kTextBaseline = popup_window_mode_ ? 15 : 18;
460 font_y_adjustment_ = kTextBaseline - font_ascent_; 448 font_y_adjustment_ = kTextBaseline - font_ascent_;
461 font_descent_ = tm.tmDescent; 449 font_descent_ = tm.tmDescent;
462 450
463 // Get the number of twips per pixel, which we need below to offset our text 451 // Get the number of twips per pixel, which we need below to offset our text
464 // by the desired number of pixels. 452 // by the desired number of pixels.
465 const long kTwipsPerPixel = kTwipsPerInch / GetDeviceCaps(dc, LOGPIXELSY); 453 const long kTwipsPerPixel = kTwipsPerInch / GetDeviceCaps(dc, LOGPIXELSY);
466 ::ReleaseDC(NULL, dc); 454 ::ReleaseDC(NULL, dc);
467 455
468 // Set the default character style -- adjust to our desired baseline and make 456 // Set the default character style -- adjust to our desired baseline.
469 // text grey.
470 CHARFORMAT cf = {0}; 457 CHARFORMAT cf = {0};
471 cf.dwMask = CFM_OFFSET | CFM_COLOR; 458 cf.dwMask = CFM_OFFSET;
472 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel; 459 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel;
473 cf.crTextColor = GetSysColor(COLOR_GRAYTEXT);
474 SetDefaultCharFormat(cf); 460 SetDefaultCharFormat(cf);
475 461
476 // By default RichEdit has a drop target. Revoke it so that we can install our 462 // By default RichEdit has a drop target. Revoke it so that we can install our
477 // own. Revoke takes care of deleting the existing one. 463 // own. Revoke takes care of deleting the existing one.
478 RevokeDragDrop(m_hWnd); 464 RevokeDragDrop(m_hWnd);
479 465
480 // Register our drop target. RichEdit appears to invoke RevokeDropTarget when 466 // Register our drop target. RichEdit appears to invoke RevokeDropTarget when
481 // done so that we don't have to explicitly. 467 // done so that we don't have to explicitly.
482 if (!popup_window_mode_) { 468 if (!popup_window_mode_) {
483 scoped_refptr<EditDropTarget> drop_target = new EditDropTarget(this); 469 scoped_refptr<EditDropTarget> drop_target = new EditDropTarget(this);
(...skipping 27 matching lines...) Expand all
511 State(selection, saved_selection_for_focus_change_))); 497 State(selection, saved_selection_for_focus_change_)));
512 } 498 }
513 499
514 void AutocompleteEditViewWin::Update( 500 void AutocompleteEditViewWin::Update(
515 const TabContents* tab_for_state_restoring) { 501 const TabContents* tab_for_state_restoring) {
516 const bool visibly_changed_permanent_text = 502 const bool visibly_changed_permanent_text =
517 model_->UpdatePermanentText(toolbar_model_->GetText()); 503 model_->UpdatePermanentText(toolbar_model_->GetText());
518 504
519 const ToolbarModel::SecurityLevel security_level = 505 const ToolbarModel::SecurityLevel security_level =
520 toolbar_model_->GetSchemeSecurityLevel(); 506 toolbar_model_->GetSchemeSecurityLevel();
521 const COLORREF background_color = skia::SkColorToCOLORREF( 507 const COLORREF background_color =
522 LocationBarView::kBackgroundColorByLevel[security_level]); 508 skia::SkColorToCOLORREF(LocationBarView::GetColor(
509 security_level == ToolbarModel::SECURE, LocationBarView::BACKGROUND));
523 const bool changed_security_level = 510 const bool changed_security_level =
524 (security_level != scheme_security_level_); 511 (security_level != scheme_security_level_);
525 512
526 // Bail early when no visible state will actually change (prevents an 513 // Bail early when no visible state will actually change (prevents an
527 // unnecessary ScopedFreeze, and thus UpdateWindow()). 514 // unnecessary ScopedFreeze, and thus UpdateWindow()).
528 if ((background_color == background_color_) && !changed_security_level && 515 if ((background_color == background_color_) && !changed_security_level &&
529 !visibly_changed_permanent_text && !tab_for_state_restoring) 516 !visibly_changed_permanent_text && !tab_for_state_restoring)
530 return; 517 return;
531 518
532 // Update our local state as desired. We set scheme_security_level_ here so 519 // Update our local state as desired. We set scheme_security_level_ here so
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after
2009 // And Go system uses. 1996 // And Go system uses.
2010 url_parse::Component scheme, host; 1997 url_parse::Component scheme, host;
2011 AutocompleteInput::ParseForEmphasizeComponents( 1998 AutocompleteInput::ParseForEmphasizeComponents(
2012 GetText(), model_->GetDesiredTLD(), &scheme, &host); 1999 GetText(), model_->GetDesiredTLD(), &scheme, &host);
2013 const bool emphasize = model_->CurrentTextIsURL() && (host.len > 0); 2000 const bool emphasize = model_->CurrentTextIsURL() && (host.len > 0);
2014 2001
2015 // Set the baseline emphasis. 2002 // Set the baseline emphasis.
2016 CHARFORMAT cf = {0}; 2003 CHARFORMAT cf = {0};
2017 cf.dwMask = CFM_COLOR; 2004 cf.dwMask = CFM_COLOR;
2018 cf.dwEffects = 0; 2005 cf.dwEffects = 0;
2019 cf.crTextColor = GetSysColor(emphasize ? COLOR_GRAYTEXT : COLOR_WINDOWTEXT); 2006 const bool is_secure = (scheme_security_level_ == ToolbarModel::SECURE);
2007 // If we're going to emphasize parts of the text, then the baseline state
2008 // should be "de-emphasized". If not, then everything should be rendered in
2009 // the standard text color.
2010 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor(is_secure,
2011 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT));
2020 SelectAll(false); 2012 SelectAll(false);
2021 SetSelectionCharFormat(cf); 2013 SetSelectionCharFormat(cf);
2022 2014
2023 if (emphasize) { 2015 if (emphasize) {
2024 // We've found a host name, give it more emphasis. 2016 // We've found a host name, give it more emphasis.
2025 cf.crTextColor = GetSysColor(COLOR_WINDOWTEXT); 2017 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor(
2018 is_secure, LocationBarView::TEXT));
2026 SetSelection(host.begin, host.end()); 2019 SetSelection(host.begin, host.end());
2027 SetSelectionCharFormat(cf); 2020 SetSelectionCharFormat(cf);
2028 } 2021 }
2029 2022
2030 // Emphasize the scheme for security UI display purposes (if necessary). 2023 // Emphasize the scheme for security UI display purposes (if necessary).
2031 insecure_scheme_component_.reset(); 2024 insecure_scheme_component_.reset();
2032 if (!model_->user_input_in_progress() && scheme.is_nonempty() && 2025 if (!model_->user_input_in_progress() && scheme.is_nonempty() &&
2033 (scheme_security_level_ != ToolbarModel::NORMAL)) { 2026 (scheme_security_level_ != ToolbarModel::NORMAL)) {
2034 if (scheme_security_level_ == ToolbarModel::SECURE) { 2027 if (!is_secure) {
2035 cf.crTextColor = kSecureSchemeColor;
2036 } else {
2037 insecure_scheme_component_.begin = scheme.begin; 2028 insecure_scheme_component_.begin = scheme.begin;
2038 insecure_scheme_component_.len = scheme.len; 2029 insecure_scheme_component_.len = scheme.len;
2039 cf.crTextColor = kInsecureSchemeColor;
2040 } 2030 }
2031 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor(
2032 is_secure, LocationBarView::SECURITY_TEXT));
2041 SetSelection(scheme.begin, scheme.end()); 2033 SetSelection(scheme.begin, scheme.end());
2042 SetSelectionCharFormat(cf); 2034 SetSelectionCharFormat(cf);
2043 } 2035 }
2044 2036
2045 // Restore the selection. 2037 // Restore the selection.
2046 SetSelectionRange(saved_sel); 2038 SetSelectionRange(saved_sel);
2047 } 2039 }
2048 2040
2049 void AutocompleteEditViewWin::EraseTopOfSelection( 2041 void AutocompleteEditViewWin::EraseTopOfSelection(
2050 CDC* dc, const CRect& client_rect, const CRect& paint_clip_rect) { 2042 CDC* dc, const CRect& client_rect, const CRect& paint_clip_rect) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2127 const SkRect selection_rect = { 2119 const SkRect selection_rect = {
2128 SkIntToScalar(PosFromChar(sel.cpMin).x - scheme_rect.left), 2120 SkIntToScalar(PosFromChar(sel.cpMin).x - scheme_rect.left),
2129 SkIntToScalar(0), 2121 SkIntToScalar(0),
2130 SkIntToScalar(PosFromChar(sel.cpMax).x - scheme_rect.left), 2122 SkIntToScalar(PosFromChar(sel.cpMax).x - scheme_rect.left),
2131 SkIntToScalar(scheme_rect.Height()) }; 2123 SkIntToScalar(scheme_rect.Height()) };
2132 2124
2133 // Draw the unselected portion of the stroke. 2125 // Draw the unselected portion of the stroke.
2134 canvas.save(); 2126 canvas.save();
2135 if (selection_rect.isEmpty() || 2127 if (selection_rect.isEmpty() ||
2136 canvas.clipRect(selection_rect, SkRegion::kDifference_Op)) { 2128 canvas.clipRect(selection_rect, SkRegion::kDifference_Op)) {
2137 paint.setColor(kSchemeStrikeoutColor); 2129 paint.setColor(LocationBarView::GetColor(false,
2130 LocationBarView::SCHEME_STRIKEOUT));
2138 canvas.drawLine(start_point.fX, start_point.fY, 2131 canvas.drawLine(start_point.fX, start_point.fY,
2139 end_point.fX, end_point.fY, paint); 2132 end_point.fX, end_point.fY, paint);
2140 } 2133 }
2141 canvas.restore(); 2134 canvas.restore();
2142 2135
2143 // Draw the selected portion of the stroke. 2136 // Draw the selected portion of the stroke.
2144 if (!selection_rect.isEmpty() && canvas.clipRect(selection_rect)) { 2137 if (!selection_rect.isEmpty() && canvas.clipRect(selection_rect)) {
2145 paint.setColor(kSchemeSelectedStrikeoutColor); 2138 paint.setColor(LocationBarView::GetColor(false,
2139 LocationBarView::SELECTED_TEXT));
2146 canvas.drawLine(start_point.fX, start_point.fY, 2140 canvas.drawLine(start_point.fX, start_point.fY,
2147 end_point.fX, end_point.fY, paint); 2141 end_point.fX, end_point.fY, paint);
2148 } 2142 }
2149 2143
2150 // Now copy what we drew to the target HDC. 2144 // Now copy what we drew to the target HDC.
2151 canvas.getTopPlatformDevice().drawToHDC(hdc, 2145 canvas.getTopPlatformDevice().drawToHDC(hdc,
2152 scheme_rect.left + canvas_paint_clip_rect.left - canvas_clip_rect.left, 2146 scheme_rect.left + canvas_paint_clip_rect.left - canvas_clip_rect.left,
2153 std::max(scheme_rect.top, client_rect.top) + canvas_paint_clip_rect.top - 2147 std::max(scheme_rect.top, client_rect.top) + canvas_paint_clip_rect.top -
2154 canvas_clip_rect.top, &canvas_paint_clip_rect); 2148 canvas_clip_rect.top, &canvas_paint_clip_rect);
2155 } 2149 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
2374 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO, 2368 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO,
2375 IDS_PASTE_AND_GO); 2369 IDS_PASTE_AND_GO);
2376 context_menu_contents_->AddSeparator(); 2370 context_menu_contents_->AddSeparator();
2377 context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL); 2371 context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL);
2378 context_menu_contents_->AddSeparator(); 2372 context_menu_contents_->AddSeparator();
2379 context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES, 2373 context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES,
2380 IDS_EDIT_SEARCH_ENGINES); 2374 IDS_EDIT_SEARCH_ENGINES);
2381 } 2375 }
2382 context_menu_.reset(new views::Menu2(context_menu_contents_.get())); 2376 context_menu_.reset(new views::Menu2(context_menu_contents_.get()));
2383 } 2377 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc ('k') | chrome/browser/toolbar_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698