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 <algorithm> | 7 #include <algorithm> |
8 #include <locale> | 8 #include <locale> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 411 matching lines...) Loading... |
422 CreateTextServices(NULL, NULL, NULL); | 422 CreateTextServices(NULL, NULL, NULL); |
423 | 423 |
424 model_->SetPopupModel(popup_view_->GetModel()); | 424 model_->SetPopupModel(popup_view_->GetModel()); |
425 | 425 |
426 saved_selection_for_focus_change_.cpMin = -1; | 426 saved_selection_for_focus_change_.cpMin = -1; |
427 | 427 |
428 g_paint_patcher.Pointer()->RefPatch(); | 428 g_paint_patcher.Pointer()->RefPatch(); |
429 | 429 |
430 Create(hwnd, 0, 0, 0, l10n_util::GetExtendedStyles()); | 430 Create(hwnd, 0, 0, 0, l10n_util::GetExtendedStyles()); |
431 SetReadOnly(popup_window_mode_); | 431 SetReadOnly(popup_window_mode_); |
432 SetFont(font_.hfont()); | 432 SetFont(font_.GetNativeFont()); |
433 | 433 |
434 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as | 434 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as |
435 // of Rich Edit 2.0 onward. | 435 // of Rich Edit 2.0 onward. |
436 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, | 436 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, |
437 reinterpret_cast<LPARAM>(&WordBreakProc)); | 437 reinterpret_cast<LPARAM>(&WordBreakProc)); |
438 | 438 |
439 // Get the metrics for the font. | 439 // Get the metrics for the font. |
440 HDC dc = ::GetDC(NULL); | 440 HDC dc = ::GetDC(NULL); |
441 SelectObject(dc, font_.hfont()); | 441 SelectObject(dc, font_.GetNativeFont()); |
442 TEXTMETRIC tm = {0}; | 442 TEXTMETRIC tm = {0}; |
443 GetTextMetrics(dc, &tm); | 443 GetTextMetrics(dc, &tm); |
444 const float kXHeightRatio = 0.7f; // The ratio of a font's x-height to its | 444 const float kXHeightRatio = 0.7f; // The ratio of a font's x-height to its |
445 // cap height. Sadly, Windows doesn't | 445 // cap height. Sadly, Windows doesn't |
446 // provide a true value for a font's | 446 // provide a true value for a font's |
447 // x-height in its text metrics, so we | 447 // x-height in its text metrics, so we |
448 // approximate. | 448 // approximate. |
449 font_x_height_ = static_cast<int>((static_cast<float>(font_.baseline() - | 449 font_x_height_ = static_cast<int>((static_cast<float>(font_.GetBaseline() - |
450 tm.tmInternalLeading) * kXHeightRatio) + 0.5); | 450 tm.tmInternalLeading) * kXHeightRatio) + 0.5); |
451 // The distance from the top of the field to the desired baseline of the | 451 // The distance from the top of the field to the desired baseline of the |
452 // rendered text. | 452 // rendered text. |
453 const int kTextBaseline = popup_window_mode_ ? 15 : 18; | 453 const int kTextBaseline = popup_window_mode_ ? 15 : 18; |
454 font_y_adjustment_ = kTextBaseline - font_.baseline(); | 454 font_y_adjustment_ = kTextBaseline - font_.GetBaseline(); |
455 | 455 |
456 // Get the number of twips per pixel, which we need below to offset our text | 456 // Get the number of twips per pixel, which we need below to offset our text |
457 // by the desired number of pixels. | 457 // by the desired number of pixels. |
458 const long kTwipsPerPixel = kTwipsPerInch / GetDeviceCaps(dc, LOGPIXELSY); | 458 const long kTwipsPerPixel = kTwipsPerInch / GetDeviceCaps(dc, LOGPIXELSY); |
459 ::ReleaseDC(NULL, dc); | 459 ::ReleaseDC(NULL, dc); |
460 | 460 |
461 // Set the default character style -- adjust to our desired baseline. | 461 // Set the default character style -- adjust to our desired baseline. |
462 CHARFORMAT cf = {0}; | 462 CHARFORMAT cf = {0}; |
463 cf.dwMask = CFM_OFFSET; | 463 cf.dwMask = CFM_OFFSET; |
464 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel; | 464 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel; |
(...skipping 1677 matching lines...) Loading... |
2142 // Calculate the rect, in window coordinates, containing the portion of the | 2142 // Calculate the rect, in window coordinates, containing the portion of the |
2143 // scheme where we'll be drawing the slash. Vertically, we draw across one | 2143 // scheme where we'll be drawing the slash. Vertically, we draw across one |
2144 // x-height of text, plus an additional 3 stroke diameters (the stroke width | 2144 // x-height of text, plus an additional 3 stroke diameters (the stroke width |
2145 // plus a half-stroke width of space between the stroke and the text, both | 2145 // plus a half-stroke width of space between the stroke and the text, both |
2146 // above and below the text). | 2146 // above and below the text). |
2147 const int font_top = client_rect.top + font_y_adjustment_; | 2147 const int font_top = client_rect.top + font_y_adjustment_; |
2148 const SkScalar kStrokeWidthPixels = SkIntToScalar(2); | 2148 const SkScalar kStrokeWidthPixels = SkIntToScalar(2); |
2149 const int kAdditionalSpaceOutsideFont = | 2149 const int kAdditionalSpaceOutsideFont = |
2150 static_cast<int>(ceil(kStrokeWidthPixels * 1.5f)); | 2150 static_cast<int>(ceil(kStrokeWidthPixels * 1.5f)); |
2151 const CRect scheme_rect(PosFromChar(insecure_scheme_component_.begin).x, | 2151 const CRect scheme_rect(PosFromChar(insecure_scheme_component_.begin).x, |
2152 font_top + font_.baseline() - font_x_height_ - | 2152 font_top + font_.GetBaseline() - font_x_height_ - |
2153 kAdditionalSpaceOutsideFont, | 2153 kAdditionalSpaceOutsideFont, |
2154 PosFromChar(insecure_scheme_component_.end()).x, | 2154 PosFromChar(insecure_scheme_component_.end()).x, |
2155 font_top + font_.baseline() + | 2155 font_top + font_.GetBaseline() + |
2156 kAdditionalSpaceOutsideFont); | 2156 kAdditionalSpaceOutsideFont); |
2157 | 2157 |
2158 // Clip to the portion we care about and translate to canvas coordinates | 2158 // Clip to the portion we care about and translate to canvas coordinates |
2159 // (see the canvas creation below) for use later. | 2159 // (see the canvas creation below) for use later. |
2160 CRect canvas_clip_rect, canvas_paint_clip_rect; | 2160 CRect canvas_clip_rect, canvas_paint_clip_rect; |
2161 canvas_clip_rect.IntersectRect(scheme_rect, client_rect); | 2161 canvas_clip_rect.IntersectRect(scheme_rect, client_rect); |
2162 canvas_paint_clip_rect.IntersectRect(canvas_clip_rect, paint_clip_rect); | 2162 canvas_paint_clip_rect.IntersectRect(canvas_clip_rect, paint_clip_rect); |
2163 if (canvas_paint_clip_rect.IsRectNull()) | 2163 if (canvas_paint_clip_rect.IsRectNull()) |
2164 return; // We don't need to paint any of this region, so just bail early. | 2164 return; // We don't need to paint any of this region, so just bail early. |
2165 canvas_clip_rect.OffsetRect(-scheme_rect.left, -scheme_rect.top); | 2165 canvas_clip_rect.OffsetRect(-scheme_rect.left, -scheme_rect.top); |
(...skipping 60 matching lines...) Loading... |
2226 | 2226 |
2227 void AutocompleteEditViewWin::DrawDropHighlight( | 2227 void AutocompleteEditViewWin::DrawDropHighlight( |
2228 HDC hdc, const CRect& client_rect, const CRect& paint_clip_rect) { | 2228 HDC hdc, const CRect& client_rect, const CRect& paint_clip_rect) { |
2229 DCHECK(drop_highlight_position_ != -1); | 2229 DCHECK(drop_highlight_position_ != -1); |
2230 | 2230 |
2231 const int highlight_y = client_rect.top + font_y_adjustment_; | 2231 const int highlight_y = client_rect.top + font_y_adjustment_; |
2232 const int highlight_x = PosFromChar(drop_highlight_position_).x - 1; | 2232 const int highlight_x = PosFromChar(drop_highlight_position_).x - 1; |
2233 const CRect highlight_rect(highlight_x, | 2233 const CRect highlight_rect(highlight_x, |
2234 highlight_y, | 2234 highlight_y, |
2235 highlight_x + 1, | 2235 highlight_x + 1, |
2236 highlight_y + font_.height()); | 2236 highlight_y + font_.GetHeight()); |
2237 | 2237 |
2238 // Clip the highlight to the region being painted. | 2238 // Clip the highlight to the region being painted. |
2239 CRect clip_rect; | 2239 CRect clip_rect; |
2240 clip_rect.IntersectRect(highlight_rect, paint_clip_rect); | 2240 clip_rect.IntersectRect(highlight_rect, paint_clip_rect); |
2241 if (clip_rect.IsRectNull()) | 2241 if (clip_rect.IsRectNull()) |
2242 return; | 2242 return; |
2243 | 2243 |
2244 HGDIOBJ last_pen = SelectObject(hdc, CreatePen(PS_SOLID, 1, RGB(0, 0, 0))); | 2244 HGDIOBJ last_pen = SelectObject(hdc, CreatePen(PS_SOLID, 1, RGB(0, 0, 0))); |
2245 MoveToEx(hdc, clip_rect.left, clip_rect.top, NULL); | 2245 MoveToEx(hdc, clip_rect.left, clip_rect.top, NULL); |
2246 LineTo(hdc, clip_rect.left, clip_rect.bottom); | 2246 LineTo(hdc, clip_rect.left, clip_rect.bottom); |
(...skipping 176 matching lines...) Loading... |
2423 // a drag regardless of the y-coordinate. | 2423 // a drag regardless of the y-coordinate. |
2424 possible_drag_ = (point.x >= min_sel_location.x) && | 2424 possible_drag_ = (point.x >= min_sel_location.x) && |
2425 (point.x < max_sel_location.x); | 2425 (point.x < max_sel_location.x); |
2426 } | 2426 } |
2427 } | 2427 } |
2428 | 2428 |
2429 void AutocompleteEditViewWin::RepaintDropHighlight(int position) { | 2429 void AutocompleteEditViewWin::RepaintDropHighlight(int position) { |
2430 if ((position != -1) && (position <= GetTextLength())) { | 2430 if ((position != -1) && (position <= GetTextLength())) { |
2431 const POINT min_loc(PosFromChar(position)); | 2431 const POINT min_loc(PosFromChar(position)); |
2432 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_, | 2432 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_, |
2433 min_loc.x + 2, font_.height() + font_y_adjustment_}; | 2433 min_loc.x + 2, font_.GetHeight() + font_y_adjustment_}; |
2434 InvalidateRect(&highlight_bounds, false); | 2434 InvalidateRect(&highlight_bounds, false); |
2435 } | 2435 } |
2436 } | 2436 } |
2437 | 2437 |
2438 void AutocompleteEditViewWin::BuildContextMenu() { | 2438 void AutocompleteEditViewWin::BuildContextMenu() { |
2439 if (context_menu_contents_.get()) | 2439 if (context_menu_contents_.get()) |
2440 return; | 2440 return; |
2441 | 2441 |
2442 context_menu_contents_.reset(new menus::SimpleMenuModel(this)); | 2442 context_menu_contents_.reset(new menus::SimpleMenuModel(this)); |
2443 // Set up context menu. | 2443 // Set up context menu. |
(...skipping 33 matching lines...) Loading... |
2477 void AutocompleteEditViewWin::TrackMousePosition(MouseButton button, | 2477 void AutocompleteEditViewWin::TrackMousePosition(MouseButton button, |
2478 const CPoint& point) { | 2478 const CPoint& point) { |
2479 if (gaining_focus_.get()) { | 2479 if (gaining_focus_.get()) { |
2480 // This click is giving us focus, so we need to track how much the mouse | 2480 // This click is giving us focus, so we need to track how much the mouse |
2481 // moves to see if it's a drag or just a click. Clicks should select all | 2481 // moves to see if it's a drag or just a click. Clicks should select all |
2482 // the text. | 2482 // the text. |
2483 tracking_click_[button] = true; | 2483 tracking_click_[button] = true; |
2484 click_point_[button] = point; | 2484 click_point_[button] = point; |
2485 } | 2485 } |
2486 } | 2486 } |
OLD | NEW |