OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include <richedit.h> | 8 #include <richedit.h> |
9 #include <textserv.h> | 9 #include <textserv.h> |
10 | 10 |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 tracking_click_(false), | 400 tracking_click_(false), |
401 tracking_double_click_(false), | 401 tracking_double_click_(false), |
402 double_click_time_(0), | 402 double_click_time_(0), |
403 can_discard_mousemove_(false), | 403 can_discard_mousemove_(false), |
404 ignore_ime_messages_(false), | 404 ignore_ime_messages_(false), |
405 font_(font), | 405 font_(font), |
406 possible_drag_(false), | 406 possible_drag_(false), |
407 in_drag_(false), | 407 in_drag_(false), |
408 initiated_drag_(false), | 408 initiated_drag_(false), |
409 drop_highlight_position_(-1), | 409 drop_highlight_position_(-1), |
410 background_color_(0), | 410 background_color_(skia::SkColorToCOLORREF(LocationBarView::GetColor( |
411 scheme_security_level_(ToolbarModel::NORMAL), | 411 ToolbarModel::NONE, LocationBarView::BACKGROUND))), |
| 412 security_level_(ToolbarModel::NONE), |
412 text_object_model_(NULL) { | 413 text_object_model_(NULL) { |
413 // Dummy call to a function exported by riched20.dll to ensure it sets up an | 414 // Dummy call to a function exported by riched20.dll to ensure it sets up an |
414 // import dependency on the dll. | 415 // import dependency on the dll. |
415 CreateTextServices(NULL, NULL, NULL); | 416 CreateTextServices(NULL, NULL, NULL); |
416 | 417 |
417 model_->SetPopupModel(popup_view_->GetModel()); | 418 model_->SetPopupModel(popup_view_->GetModel()); |
418 | 419 |
419 saved_selection_for_focus_change_.cpMin = -1; | 420 saved_selection_for_focus_change_.cpMin = -1; |
420 | 421 |
421 g_paint_patcher.Pointer()->RefPatch(); | 422 g_paint_patcher.Pointer()->RefPatch(); |
(...skipping 30 matching lines...) Expand all Loading... |
452 // by the desired number of pixels. | 453 // by the desired number of pixels. |
453 const long kTwipsPerPixel = kTwipsPerInch / GetDeviceCaps(dc, LOGPIXELSY); | 454 const long kTwipsPerPixel = kTwipsPerInch / GetDeviceCaps(dc, LOGPIXELSY); |
454 ::ReleaseDC(NULL, dc); | 455 ::ReleaseDC(NULL, dc); |
455 | 456 |
456 // Set the default character style -- adjust to our desired baseline. | 457 // Set the default character style -- adjust to our desired baseline. |
457 CHARFORMAT cf = {0}; | 458 CHARFORMAT cf = {0}; |
458 cf.dwMask = CFM_OFFSET; | 459 cf.dwMask = CFM_OFFSET; |
459 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel; | 460 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel; |
460 SetDefaultCharFormat(cf); | 461 SetDefaultCharFormat(cf); |
461 | 462 |
| 463 SetBackgroundColor(background_color_); |
| 464 |
462 // By default RichEdit has a drop target. Revoke it so that we can install our | 465 // By default RichEdit has a drop target. Revoke it so that we can install our |
463 // own. Revoke takes care of deleting the existing one. | 466 // own. Revoke takes care of deleting the existing one. |
464 RevokeDragDrop(m_hWnd); | 467 RevokeDragDrop(m_hWnd); |
465 | 468 |
466 // Register our drop target. RichEdit appears to invoke RevokeDropTarget when | 469 // Register our drop target. RichEdit appears to invoke RevokeDropTarget when |
467 // done so that we don't have to explicitly. | 470 // done so that we don't have to explicitly. |
468 if (!popup_window_mode_) { | 471 if (!popup_window_mode_) { |
469 scoped_refptr<EditDropTarget> drop_target = new EditDropTarget(this); | 472 scoped_refptr<EditDropTarget> drop_target = new EditDropTarget(this); |
470 RegisterDragDrop(m_hWnd, drop_target.get()); | 473 RegisterDragDrop(m_hWnd, drop_target.get()); |
471 } | 474 } |
(...skipping 29 matching lines...) Expand all Loading... |
501 model_state, | 504 model_state, |
502 State(selection, saved_selection_for_focus_change_))); | 505 State(selection, saved_selection_for_focus_change_))); |
503 } | 506 } |
504 | 507 |
505 void AutocompleteEditViewWin::Update( | 508 void AutocompleteEditViewWin::Update( |
506 const TabContents* tab_for_state_restoring) { | 509 const TabContents* tab_for_state_restoring) { |
507 const bool visibly_changed_permanent_text = | 510 const bool visibly_changed_permanent_text = |
508 model_->UpdatePermanentText(toolbar_model_->GetText()); | 511 model_->UpdatePermanentText(toolbar_model_->GetText()); |
509 | 512 |
510 const ToolbarModel::SecurityLevel security_level = | 513 const ToolbarModel::SecurityLevel security_level = |
511 toolbar_model_->GetSchemeSecurityLevel(); | 514 toolbar_model_->GetSecurityLevel(); |
512 const COLORREF background_color = | 515 const bool changed_security_level = (security_level != security_level_); |
513 skia::SkColorToCOLORREF(LocationBarView::GetColor( | |
514 security_level == ToolbarModel::SECURE, LocationBarView::BACKGROUND)); | |
515 const bool changed_security_level = | |
516 (security_level != scheme_security_level_); | |
517 | 516 |
518 // Bail early when no visible state will actually change (prevents an | 517 // Bail early when no visible state will actually change (prevents an |
519 // unnecessary ScopedFreeze, and thus UpdateWindow()). | 518 // unnecessary ScopedFreeze, and thus UpdateWindow()). |
520 if ((background_color == background_color_) && !changed_security_level && | 519 if (!changed_security_level && !visibly_changed_permanent_text && |
521 !visibly_changed_permanent_text && !tab_for_state_restoring) | 520 !tab_for_state_restoring) |
522 return; | 521 return; |
523 | 522 |
524 // Update our local state as desired. We set scheme_security_level_ here so | 523 // Update our local state as desired. We set security_level_ here so it will |
525 // it will already be correct before we get to any RevertAll()s below and use | 524 // already be correct before we get to any RevertAll()s below and use it. |
526 // it. | 525 security_level_ = security_level; |
527 ScopedFreeze freeze(this, GetTextObjectModel()); | |
528 if (background_color_ != background_color) { | |
529 background_color_ = background_color; | |
530 SetBackgroundColor(background_color_); | |
531 } | |
532 scheme_security_level_ = security_level; | |
533 | 526 |
534 // When we're switching to a new tab, restore its state, if any. | 527 // When we're switching to a new tab, restore its state, if any. |
| 528 ScopedFreeze freeze(this, GetTextObjectModel()); |
535 if (tab_for_state_restoring) { | 529 if (tab_for_state_restoring) { |
536 // Make sure we reset our own state first. The new tab may not have any | 530 // Make sure we reset our own state first. The new tab may not have any |
537 // saved state, or it may not have had input in progress, in which case we | 531 // saved state, or it may not have had input in progress, in which case we |
538 // won't overwrite all our local state. | 532 // won't overwrite all our local state. |
539 RevertAll(); | 533 RevertAll(); |
540 | 534 |
541 const AutocompleteEditState* state = GetStateAccessor()->GetProperty( | 535 const AutocompleteEditState* state = GetStateAccessor()->GetProperty( |
542 tab_for_state_restoring->property_bag()); | 536 tab_for_state_restoring->property_bag()); |
543 if (state) { | 537 if (state) { |
544 model_->RestoreState(state->model_state); | 538 model_->RestoreState(state->model_state); |
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2053 // be treated as a search or a navigation, and is the same method the Paste | 2047 // be treated as a search or a navigation, and is the same method the Paste |
2054 // And Go system uses. | 2048 // And Go system uses. |
2055 url_parse::Component scheme, host; | 2049 url_parse::Component scheme, host; |
2056 AutocompleteInput::ParseForEmphasizeComponents( | 2050 AutocompleteInput::ParseForEmphasizeComponents( |
2057 GetText(), model_->GetDesiredTLD(), &scheme, &host); | 2051 GetText(), model_->GetDesiredTLD(), &scheme, &host); |
2058 const bool emphasize = model_->CurrentTextIsURL() && (host.len > 0); | 2052 const bool emphasize = model_->CurrentTextIsURL() && (host.len > 0); |
2059 | 2053 |
2060 // Set the baseline emphasis. | 2054 // Set the baseline emphasis. |
2061 CHARFORMAT cf = {0}; | 2055 CHARFORMAT cf = {0}; |
2062 cf.dwMask = CFM_COLOR; | 2056 cf.dwMask = CFM_COLOR; |
2063 const bool is_secure = (scheme_security_level_ == ToolbarModel::SECURE); | |
2064 // If we're going to emphasize parts of the text, then the baseline state | 2057 // If we're going to emphasize parts of the text, then the baseline state |
2065 // should be "de-emphasized". If not, then everything should be rendered in | 2058 // should be "de-emphasized". If not, then everything should be rendered in |
2066 // the standard text color. | 2059 // the standard text color. |
2067 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor(is_secure, | 2060 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor( |
| 2061 security_level_, |
2068 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | 2062 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); |
2069 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets the | 2063 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets the |
2070 // format that will get applied to text added in the future, not to text | 2064 // format that will get applied to text added in the future, not to text |
2071 // already in the edit. | 2065 // already in the edit. |
2072 SelectAll(false); | 2066 SelectAll(false); |
2073 SetSelectionCharFormat(cf); | 2067 SetSelectionCharFormat(cf); |
2074 | 2068 |
2075 if (emphasize) { | 2069 if (emphasize) { |
2076 // We've found a host name, give it more emphasis. | 2070 // We've found a host name, give it more emphasis. |
2077 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor( | 2071 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor( |
2078 is_secure, LocationBarView::TEXT)); | 2072 security_level_, LocationBarView::TEXT)); |
2079 SetSelection(host.begin, host.end()); | 2073 SetSelection(host.begin, host.end()); |
2080 SetSelectionCharFormat(cf); | 2074 SetSelectionCharFormat(cf); |
2081 } | 2075 } |
2082 | 2076 |
2083 // Emphasize the scheme for security UI display purposes (if necessary). | 2077 // Emphasize the scheme for security UI display purposes (if necessary). |
2084 insecure_scheme_component_.reset(); | 2078 insecure_scheme_component_.reset(); |
2085 if (!model_->user_input_in_progress() && scheme.is_nonempty() && | 2079 if (!model_->user_input_in_progress() && scheme.is_nonempty() && |
2086 (scheme_security_level_ != ToolbarModel::NORMAL)) { | 2080 (security_level_ != ToolbarModel::NONE)) { |
2087 if (!is_secure) { | 2081 if (security_level_ == ToolbarModel::SECURITY_ERROR) { |
2088 insecure_scheme_component_.begin = scheme.begin; | 2082 insecure_scheme_component_.begin = scheme.begin; |
2089 insecure_scheme_component_.len = scheme.len; | 2083 insecure_scheme_component_.len = scheme.len; |
2090 } | 2084 } |
2091 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor( | 2085 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor( |
2092 is_secure, LocationBarView::SECURITY_TEXT)); | 2086 security_level_, LocationBarView::SECURITY_TEXT)); |
2093 SetSelection(scheme.begin, scheme.end()); | 2087 SetSelection(scheme.begin, scheme.end()); |
2094 SetSelectionCharFormat(cf); | 2088 SetSelectionCharFormat(cf); |
2095 } | 2089 } |
2096 | 2090 |
2097 // Restore the selection. | 2091 // Restore the selection. |
2098 SetSelectionRange(saved_sel); | 2092 SetSelectionRange(saved_sel); |
2099 } | 2093 } |
2100 | 2094 |
2101 void AutocompleteEditViewWin::EraseTopOfSelection( | 2095 void AutocompleteEditViewWin::EraseTopOfSelection( |
2102 CDC* dc, const CRect& client_rect, const CRect& paint_clip_rect) { | 2096 CDC* dc, const CRect& client_rect, const CRect& paint_clip_rect) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2176 const SkRect selection_rect = { | 2170 const SkRect selection_rect = { |
2177 SkIntToScalar(PosFromChar(sel.cpMin).x - scheme_rect.left), | 2171 SkIntToScalar(PosFromChar(sel.cpMin).x - scheme_rect.left), |
2178 SkIntToScalar(0), | 2172 SkIntToScalar(0), |
2179 SkIntToScalar(PosFromChar(sel.cpMax).x - scheme_rect.left), | 2173 SkIntToScalar(PosFromChar(sel.cpMax).x - scheme_rect.left), |
2180 SkIntToScalar(scheme_rect.Height()) }; | 2174 SkIntToScalar(scheme_rect.Height()) }; |
2181 | 2175 |
2182 // Draw the unselected portion of the stroke. | 2176 // Draw the unselected portion of the stroke. |
2183 canvas.save(); | 2177 canvas.save(); |
2184 if (selection_rect.isEmpty() || | 2178 if (selection_rect.isEmpty() || |
2185 canvas.clipRect(selection_rect, SkRegion::kDifference_Op)) { | 2179 canvas.clipRect(selection_rect, SkRegion::kDifference_Op)) { |
2186 paint.setColor(LocationBarView::GetColor(false, | 2180 paint.setColor(LocationBarView::GetColor(security_level_, |
2187 LocationBarView::SCHEME_STRIKEOUT)); | 2181 LocationBarView::SECURITY_TEXT)); |
2188 canvas.drawLine(start_point.fX, start_point.fY, | 2182 canvas.drawLine(start_point.fX, start_point.fY, |
2189 end_point.fX, end_point.fY, paint); | 2183 end_point.fX, end_point.fY, paint); |
2190 } | 2184 } |
2191 canvas.restore(); | 2185 canvas.restore(); |
2192 | 2186 |
2193 // Draw the selected portion of the stroke. | 2187 // Draw the selected portion of the stroke. |
2194 if (!selection_rect.isEmpty() && canvas.clipRect(selection_rect)) { | 2188 if (!selection_rect.isEmpty() && canvas.clipRect(selection_rect)) { |
2195 paint.setColor(LocationBarView::GetColor(false, | 2189 paint.setColor(LocationBarView::GetColor(security_level_, |
2196 LocationBarView::SELECTED_TEXT)); | 2190 LocationBarView::SELECTED_TEXT)); |
2197 canvas.drawLine(start_point.fX, start_point.fY, | 2191 canvas.drawLine(start_point.fX, start_point.fY, |
2198 end_point.fX, end_point.fY, paint); | 2192 end_point.fX, end_point.fY, paint); |
2199 } | 2193 } |
2200 | 2194 |
2201 // Now copy what we drew to the target HDC. | 2195 // Now copy what we drew to the target HDC. |
2202 canvas.getTopPlatformDevice().drawToHDC(hdc, | 2196 canvas.getTopPlatformDevice().drawToHDC(hdc, |
2203 scheme_rect.left + canvas_paint_clip_rect.left - canvas_clip_rect.left, | 2197 scheme_rect.left + canvas_paint_clip_rect.left - canvas_clip_rect.left, |
2204 std::max(scheme_rect.top, client_rect.top) + canvas_paint_clip_rect.top - | 2198 std::max(scheme_rect.top, client_rect.top) + canvas_paint_clip_rect.top - |
2205 canvas_clip_rect.top, &canvas_paint_clip_rect); | 2199 canvas_clip_rect.top, &canvas_paint_clip_rect); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2432 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO, | 2426 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO, |
2433 IDS_PASTE_AND_GO); | 2427 IDS_PASTE_AND_GO); |
2434 context_menu_contents_->AddSeparator(); | 2428 context_menu_contents_->AddSeparator(); |
2435 context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL); | 2429 context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL); |
2436 context_menu_contents_->AddSeparator(); | 2430 context_menu_contents_->AddSeparator(); |
2437 context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES, | 2431 context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES, |
2438 IDS_EDIT_SEARCH_ENGINES); | 2432 IDS_EDIT_SEARCH_ENGINES); |
2439 } | 2433 } |
2440 context_menu_.reset(new views::Menu2(context_menu_contents_.get())); | 2434 context_menu_.reset(new views::Menu2(context_menu_contents_.get())); |
2441 } | 2435 } |
OLD | NEW |