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

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

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

Powered by Google App Engine
This is Rietveld 408576698