| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/ui/views/omnibox/omnibox_view_win.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <locale> | 8 #include <locale> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 290 } |
| 291 edit_->SetDropHighlightPosition(drop_position); | 291 edit_->SetDropHighlightPosition(drop_position); |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 void OmniboxViewWin::EditDropTarget::ResetDropHighlights() { | 295 void OmniboxViewWin::EditDropTarget::ResetDropHighlights() { |
| 296 if (drag_has_string_) | 296 if (drag_has_string_) |
| 297 edit_->SetDropHighlightPosition(-1); | 297 edit_->SetDropHighlightPosition(-1); |
| 298 } | 298 } |
| 299 | 299 |
| 300 | |
| 301 /////////////////////////////////////////////////////////////////////////////// | 300 /////////////////////////////////////////////////////////////////////////////// |
| 302 // Helper classes | 301 // Helper classes |
| 303 | 302 |
| 304 OmniboxViewWin::ScopedFreeze::ScopedFreeze(OmniboxViewWin* edit, | 303 OmniboxViewWin::ScopedFreeze::ScopedFreeze(OmniboxViewWin* edit, |
| 305 ITextDocument* text_object_model) | 304 ITextDocument* text_object_model) |
| 306 : edit_(edit), | 305 : edit_(edit), |
| 307 text_object_model_(text_object_model) { | 306 text_object_model_(text_object_model) { |
| 308 // Freeze the screen. | 307 // Freeze the screen. |
| 309 if (text_object_model_) { | 308 if (text_object_model_) { |
| 310 long count; | 309 long count; |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1511 ScopedFreeze freeze(this, GetTextObjectModel()); | 1510 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 1512 OnBeforePossibleChange(); | 1511 OnBeforePossibleChange(); |
| 1513 LRESULT result = DefWindowProc(message, wparam, lparam); | 1512 LRESULT result = DefWindowProc(message, wparam, lparam); |
| 1514 // Force an IME composition confirmation operation to trigger the text_changed | 1513 // Force an IME composition confirmation operation to trigger the text_changed |
| 1515 // code in OnAfterPossibleChange(), even if identical contents are confirmed, | 1514 // code in OnAfterPossibleChange(), even if identical contents are confirmed, |
| 1516 // to make sure the model can update its internal states correctly. | 1515 // to make sure the model can update its internal states correctly. |
| 1517 OnAfterPossibleChangeInternal((lparam & GCS_RESULTSTR) != 0); | 1516 OnAfterPossibleChangeInternal((lparam & GCS_RESULTSTR) != 0); |
| 1518 return result; | 1517 return result; |
| 1519 } | 1518 } |
| 1520 | 1519 |
| 1521 | |
| 1522 LRESULT OmniboxViewWin::OnImeEndComposition(UINT message, WPARAM wparam, | 1520 LRESULT OmniboxViewWin::OnImeEndComposition(UINT message, WPARAM wparam, |
| 1523 LPARAM lparam) { | 1521 LPARAM lparam) { |
| 1524 // The edit control auto-clears the selection on WM_IME_ENDCOMPOSITION, which | 1522 // The edit control auto-clears the selection on WM_IME_ENDCOMPOSITION, which |
| 1525 // means any inline autocompletion we were showing will no longer be | 1523 // means any inline autocompletion we were showing will no longer be |
| 1526 // selected, and therefore no longer replaced by further user typing. To | 1524 // selected, and therefore no longer replaced by further user typing. To |
| 1527 // avoid this we manually restore the original selection after the edit | 1525 // avoid this we manually restore the original selection after the edit |
| 1528 // handles the message. | 1526 // handles the message. |
| 1529 CHARRANGE range; | 1527 CHARRANGE range; |
| 1530 GetSel(range); | 1528 GetSel(range); |
| 1531 LRESULT result = DefWindowProc(message, wparam, lparam); | 1529 LRESULT result = DefWindowProc(message, wparam, lparam); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1743 // double_click_time_ from the current message's time even if the timer has | 1741 // double_click_time_ from the current message's time even if the timer has |
| 1744 // wrapped in between. | 1742 // wrapped in between. |
| 1745 const bool is_triple_click = tracking_double_click_ && | 1743 const bool is_triple_click = tracking_double_click_ && |
| 1746 views::NativeTextfieldWin::IsDoubleClick(double_click_point_, point, | 1744 views::NativeTextfieldWin::IsDoubleClick(double_click_point_, point, |
| 1747 GetCurrentMessage()->time - double_click_time_); | 1745 GetCurrentMessage()->time - double_click_time_); |
| 1748 tracking_double_click_ = false; | 1746 tracking_double_click_ = false; |
| 1749 | 1747 |
| 1750 if (!gaining_focus_.get() && !is_triple_click) | 1748 if (!gaining_focus_.get() && !is_triple_click) |
| 1751 OnPossibleDrag(point); | 1749 OnPossibleDrag(point); |
| 1752 | 1750 |
| 1753 | |
| 1754 // Modifying the selection counts as accepting any inline autocompletion, so | 1751 // Modifying the selection counts as accepting any inline autocompletion, so |
| 1755 // track "changes" made by clicking the mouse button. | 1752 // track "changes" made by clicking the mouse button. |
| 1756 ScopedFreeze freeze(this, GetTextObjectModel()); | 1753 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 1757 OnBeforePossibleChange(); | 1754 OnBeforePossibleChange(); |
| 1758 DefWindowProc(WM_LBUTTONDOWN, keys, | 1755 DefWindowProc(WM_LBUTTONDOWN, keys, |
| 1759 MAKELPARAM(ClipXCoordToVisibleText(point.x, is_triple_click), | 1756 MAKELPARAM(ClipXCoordToVisibleText(point.x, is_triple_click), |
| 1760 point.y)); | 1757 point.y)); |
| 1761 OnAfterPossibleChange(); | 1758 OnAfterPossibleChange(); |
| 1762 | 1759 |
| 1763 gaining_focus_.reset(); | 1760 gaining_focus_.reset(); |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2455 // should emphasize. To check for a URL, rather than using the type returned | 2452 // should emphasize. To check for a URL, rather than using the type returned |
| 2456 // by Parse(), ask the model, which will check the desired page transition for | 2453 // by Parse(), ask the model, which will check the desired page transition for |
| 2457 // this input. This can tell us whether an UNKNOWN input string is going to | 2454 // this input. This can tell us whether an UNKNOWN input string is going to |
| 2458 // be treated as a search or a navigation, and is the same method the Paste | 2455 // be treated as a search or a navigation, and is the same method the Paste |
| 2459 // And Go system uses. | 2456 // And Go system uses. |
| 2460 url_parse::Component scheme, host; | 2457 url_parse::Component scheme, host; |
| 2461 AutocompleteInput::ParseForEmphasizeComponents( | 2458 AutocompleteInput::ParseForEmphasizeComponents( |
| 2462 GetText(), model()->GetDesiredTLD(), &scheme, &host); | 2459 GetText(), model()->GetDesiredTLD(), &scheme, &host); |
| 2463 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); | 2460 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); |
| 2464 | 2461 |
| 2465 bool instant_extended_api_enabled = | |
| 2466 chrome::search::IsInstantExtendedAPIEnabled(parent_view_->profile()); | |
| 2467 | |
| 2468 // Set the baseline emphasis. | 2462 // Set the baseline emphasis. |
| 2469 CHARFORMAT cf = {0}; | 2463 CHARFORMAT cf = {0}; |
| 2470 cf.dwMask = CFM_COLOR; | 2464 cf.dwMask = CFM_COLOR; |
| 2471 // If we're going to emphasize parts of the text, then the baseline state | 2465 // If we're going to emphasize parts of the text, then the baseline state |
| 2472 // should be "de-emphasized". If not, then everything should be rendered in | 2466 // should be "de-emphasized". If not, then everything should be rendered in |
| 2473 // the standard text color. | 2467 // the standard text color. |
| 2474 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( | 2468 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( |
| 2475 security_level_, | 2469 security_level_, |
| 2476 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | 2470 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); |
| 2477 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets the | 2471 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets the |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2582 // Calculate the selection rectangle in canvas coordinates, which we'll use | 2576 // Calculate the selection rectangle in canvas coordinates, which we'll use |
| 2583 // to clip the stroke so we can draw the unselected and selected portions. | 2577 // to clip the stroke so we can draw the unselected and selected portions. |
| 2584 CHARRANGE sel; | 2578 CHARRANGE sel; |
| 2585 GetSel(sel); | 2579 GetSel(sel); |
| 2586 const SkRect selection_rect = { | 2580 const SkRect selection_rect = { |
| 2587 SkIntToScalar(PosFromChar(sel.cpMin).x - scheme_rect.left), | 2581 SkIntToScalar(PosFromChar(sel.cpMin).x - scheme_rect.left), |
| 2588 SkIntToScalar(0), | 2582 SkIntToScalar(0), |
| 2589 SkIntToScalar(PosFromChar(sel.cpMax).x - scheme_rect.left), | 2583 SkIntToScalar(PosFromChar(sel.cpMax).x - scheme_rect.left), |
| 2590 SkIntToScalar(scheme_rect.Height()) }; | 2584 SkIntToScalar(scheme_rect.Height()) }; |
| 2591 | 2585 |
| 2592 bool instant_extended_api_enabled = | |
| 2593 chrome::search::IsInstantExtendedAPIEnabled(parent_view_->profile()); | |
| 2594 | |
| 2595 // Draw the unselected portion of the stroke. | 2586 // Draw the unselected portion of the stroke. |
| 2596 sk_canvas->save(); | 2587 sk_canvas->save(); |
| 2597 if (selection_rect.isEmpty() || | 2588 if (selection_rect.isEmpty() || |
| 2598 sk_canvas->clipRect(selection_rect, SkRegion::kDifference_Op)) { | 2589 sk_canvas->clipRect(selection_rect, SkRegion::kDifference_Op)) { |
| 2599 paint.setColor(parent_view_->GetColor(security_level_, | 2590 paint.setColor(parent_view_->GetColor(security_level_, |
| 2600 LocationBarView::SECURITY_TEXT)); | 2591 LocationBarView::SECURITY_TEXT)); |
| 2601 sk_canvas->drawLine(start_point.fX, start_point.fY, | 2592 sk_canvas->drawLine(start_point.fX, start_point.fY, |
| 2602 end_point.fX, end_point.fY, paint); | 2593 end_point.fX, end_point.fY, paint); |
| 2603 } | 2594 } |
| 2604 sk_canvas->restore(); | 2595 sk_canvas->restore(); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2847 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2838 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
| 2848 } | 2839 } |
| 2849 | 2840 |
| 2850 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2841 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
| 2851 // Use font_.GetStringWidth() instead of | 2842 // Use font_.GetStringWidth() instead of |
| 2852 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2843 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
| 2853 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2844 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
| 2854 // PosFromChar(i) might return 0 when i is greater than 1. | 2845 // PosFromChar(i) might return 0 when i is greater than 1. |
| 2855 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2846 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
| 2856 } | 2847 } |
| OLD | NEW |