OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 // twips are a unit of type measurement, and RichEdit controls use them | 430 // twips are a unit of type measurement, and RichEdit controls use them |
431 // to set offsets. | 431 // to set offsets. |
432 const int kTwipsPerInch = 1440; | 432 const int kTwipsPerInch = 1440; |
433 | 433 |
434 } // namespace | 434 } // namespace |
435 | 435 |
436 OmniboxViewWin::OmniboxViewWin(OmniboxEditController* controller, | 436 OmniboxViewWin::OmniboxViewWin(OmniboxEditController* controller, |
437 ToolbarModel* toolbar_model, | 437 ToolbarModel* toolbar_model, |
438 LocationBarView* parent_view, | 438 LocationBarView* parent_view, |
439 CommandUpdater* command_updater, | 439 CommandUpdater* command_updater, |
440 bool popup_window_mode, | 440 WindowMode window_mode, |
441 views::View* location_bar, | 441 views::View* location_bar, |
442 views::View* popup_parent_view) | 442 views::View* popup_parent_view) |
443 : OmniboxView(parent_view->profile(), controller, toolbar_model, | 443 : OmniboxView(parent_view->profile(), controller, toolbar_model, |
444 command_updater), | 444 command_updater), |
445 popup_view_(OmniboxPopupContentsView::Create( | 445 popup_view_(OmniboxPopupContentsView::Create( |
446 parent_view->font(), this, model(), location_bar, | 446 parent_view->font(), this, model(), location_bar, |
447 popup_parent_view)), | 447 popup_parent_view)), |
448 parent_view_(parent_view), | 448 parent_view_(parent_view), |
449 popup_window_mode_(popup_window_mode), | 449 window_mode_(window_mode), |
450 force_hidden_(false), | 450 force_hidden_(false), |
451 tracking_click_(), | 451 tracking_click_(), |
452 tracking_double_click_(false), | 452 tracking_double_click_(false), |
453 double_click_time_(0), | 453 double_click_time_(0), |
454 can_discard_mousemove_(false), | 454 can_discard_mousemove_(false), |
455 ignore_ime_messages_(false), | 455 ignore_ime_messages_(false), |
456 delete_at_end_pressed_(false), | 456 delete_at_end_pressed_(false), |
457 font_(parent_view->font()), | 457 font_(parent_view->font()), |
458 possible_drag_(false), | 458 possible_drag_(false), |
459 in_drag_(false), | 459 in_drag_(false), |
460 initiated_drag_(false), | 460 initiated_drag_(false), |
461 drop_highlight_position_(-1), | 461 drop_highlight_position_(-1), |
462 ime_candidate_window_open_(false), | 462 ime_candidate_window_open_(false), |
463 background_color_(skia::SkColorToCOLORREF(LocationBarView::GetColor( | 463 background_color_(skia::SkColorToCOLORREF(LocationBarView::GetColor( |
464 ToolbarModel::NONE, LocationBarView::BACKGROUND))), | 464 ToolbarModel::NONE, LocationBarView::BACKGROUND))), |
465 security_level_(ToolbarModel::NONE), | 465 security_level_(ToolbarModel::NONE), |
466 text_object_model_(NULL) { | 466 text_object_model_(NULL) { |
467 // Dummy call to a function exported by riched20.dll to ensure it sets up an | 467 // Dummy call to a function exported by riched20.dll to ensure it sets up an |
468 // import dependency on the dll. | 468 // import dependency on the dll. |
469 CreateTextServices(NULL, NULL, NULL); | 469 CreateTextServices(NULL, NULL, NULL); |
470 | 470 |
471 saved_selection_for_focus_change_.cpMin = -1; | 471 saved_selection_for_focus_change_.cpMin = -1; |
472 | 472 |
473 g_paint_patcher.Pointer()->RefPatch(); | 473 g_paint_patcher.Pointer()->RefPatch(); |
474 | 474 |
475 Create(location_bar->GetWidget()->GetNativeView(), 0, 0, 0, | 475 Create(location_bar->GetWidget()->GetNativeView(), 0, 0, 0, |
476 l10n_util::GetExtendedStyles()); | 476 l10n_util::GetExtendedStyles()); |
477 SetReadOnly(popup_window_mode_); | 477 SetReadOnly(window_mode != NORMAL); |
478 SetFont(font_.GetNativeFont()); | 478 SetFont(font_.GetNativeFont()); |
479 | 479 |
480 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as | 480 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as |
481 // of Rich Edit 2.0 onward. | 481 // of Rich Edit 2.0 onward. |
482 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, | 482 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, |
483 reinterpret_cast<LPARAM>(&WordBreakProc)); | 483 reinterpret_cast<LPARAM>(&WordBreakProc)); |
484 | 484 |
| 485 if (window_mode == DISABLED) |
| 486 EnableWindow(FALSE); |
| 487 |
485 // Get the metrics for the font. | 488 // Get the metrics for the font. |
486 base::win::ScopedGetDC screen_dc(NULL); | 489 base::win::ScopedGetDC screen_dc(NULL); |
487 base::win::ScopedSelectObject font_in_dc(screen_dc, font_.GetNativeFont()); | 490 base::win::ScopedSelectObject font_in_dc(screen_dc, font_.GetNativeFont()); |
488 TEXTMETRIC tm = {0}; | 491 TEXTMETRIC tm = {0}; |
489 GetTextMetrics(screen_dc, &tm); | 492 GetTextMetrics(screen_dc, &tm); |
490 int cap_height = font_.GetBaseline() - tm.tmInternalLeading; | 493 int cap_height = font_.GetBaseline() - tm.tmInternalLeading; |
491 // The ratio of a font's x-height to its cap height. Sadly, Windows | 494 // The ratio of a font's x-height to its cap height. Sadly, Windows |
492 // doesn't provide a true value for a font's x-height in its text | 495 // doesn't provide a true value for a font's x-height in its text |
493 // metrics, so we approximate. | 496 // metrics, so we approximate. |
494 const float kXHeightRatio = 0.7f; | 497 const float kXHeightRatio = 0.7f; |
(...skipping 18 matching lines...) Expand all Loading... |
513 SetDefaultCharFormat(cf); | 516 SetDefaultCharFormat(cf); |
514 | 517 |
515 SetBackgroundColor(background_color_); | 518 SetBackgroundColor(background_color_); |
516 | 519 |
517 // By default RichEdit has a drop target. Revoke it so that we can install our | 520 // By default RichEdit has a drop target. Revoke it so that we can install our |
518 // own. Revoke takes care of deleting the existing one. | 521 // own. Revoke takes care of deleting the existing one. |
519 RevokeDragDrop(m_hWnd); | 522 RevokeDragDrop(m_hWnd); |
520 | 523 |
521 // Register our drop target. RichEdit appears to invoke RevokeDropTarget when | 524 // Register our drop target. RichEdit appears to invoke RevokeDropTarget when |
522 // done so that we don't have to explicitly. | 525 // done so that we don't have to explicitly. |
523 if (!popup_window_mode_) { | 526 if (window_mode == NORMAL) { |
524 scoped_refptr<EditDropTarget> drop_target = new EditDropTarget(this); | 527 scoped_refptr<EditDropTarget> drop_target = new EditDropTarget(this); |
525 RegisterDragDrop(m_hWnd, drop_target.get()); | 528 RegisterDragDrop(m_hWnd, drop_target.get()); |
526 } | 529 } |
527 } | 530 } |
528 | 531 |
529 OmniboxViewWin::~OmniboxViewWin() { | 532 OmniboxViewWin::~OmniboxViewWin() { |
530 // Explicitly release the text object model now that we're done with it, and | 533 // Explicitly release the text object model now that we're done with it, and |
531 // before we free the library. If the library gets unloaded before this | 534 // before we free the library. If the library gets unloaded before this |
532 // released, it becomes garbage. | 535 // released, it becomes garbage. Note that since text_object_model_ is lazy |
533 text_object_model_->Release(); | 536 // initialized, it may still be null. |
| 537 if (text_object_model_) |
| 538 text_object_model_->Release(); |
534 | 539 |
535 // We balance our reference count and unpatch when the last instance has | 540 // We balance our reference count and unpatch when the last instance has |
536 // been destroyed. This prevents us from relying on the AtExit or static | 541 // been destroyed. This prevents us from relying on the AtExit or static |
537 // destructor sequence to do our unpatching, which is generally fragile. | 542 // destructor sequence to do our unpatching, which is generally fragile. |
538 g_paint_patcher.Pointer()->DerefPatch(); | 543 g_paint_patcher.Pointer()->DerefPatch(); |
539 } | 544 } |
540 | 545 |
541 views::View* OmniboxViewWin::parent_view() const { | 546 views::View* OmniboxViewWin::parent_view() const { |
542 return parent_view_; | 547 return parent_view_; |
543 } | 548 } |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 | 1441 |
1437 void OmniboxViewWin::OnKeyDown(TCHAR key, | 1442 void OmniboxViewWin::OnKeyDown(TCHAR key, |
1438 UINT repeat_count, | 1443 UINT repeat_count, |
1439 UINT flags) { | 1444 UINT flags) { |
1440 delete_at_end_pressed_ = false; | 1445 delete_at_end_pressed_ = false; |
1441 | 1446 |
1442 if (OnKeyDownAllModes(key, repeat_count, flags)) | 1447 if (OnKeyDownAllModes(key, repeat_count, flags)) |
1443 return; | 1448 return; |
1444 | 1449 |
1445 // Make sure that we handle system key events like Alt-F4. | 1450 // Make sure that we handle system key events like Alt-F4. |
1446 if (popup_window_mode_) { | 1451 if (window_mode_ == POPUP) { |
1447 DefWindowProc(GetCurrentMessage()->message, key, MAKELPARAM(repeat_count, | 1452 DefWindowProc(GetCurrentMessage()->message, key, MAKELPARAM(repeat_count, |
1448 flags)); | 1453 flags)); |
1449 return; | 1454 return; |
1450 } | 1455 } |
1451 | 1456 |
1452 if (OnKeyDownOnlyWritable(key, repeat_count, flags)) | 1457 if (OnKeyDownOnlyWritable(key, repeat_count, flags)) |
1453 return; | 1458 return; |
1454 | 1459 |
1455 // CRichEditCtrl changes its text on WM_KEYDOWN instead of WM_CHAR for many | 1460 // CRichEditCtrl changes its text on WM_KEYDOWN instead of WM_CHAR for many |
1456 // different keys (backspace, ctrl-v, ...), so we call this in both cases. | 1461 // different keys (backspace, ctrl-v, ...), so we call this in both cases. |
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2574 InvalidateRect(&highlight_bounds, false); | 2579 InvalidateRect(&highlight_bounds, false); |
2575 } | 2580 } |
2576 } | 2581 } |
2577 | 2582 |
2578 void OmniboxViewWin::BuildContextMenu() { | 2583 void OmniboxViewWin::BuildContextMenu() { |
2579 if (context_menu_contents_.get()) | 2584 if (context_menu_contents_.get()) |
2580 return; | 2585 return; |
2581 | 2586 |
2582 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); | 2587 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); |
2583 // Set up context menu. | 2588 // Set up context menu. |
2584 if (popup_window_mode_) { | 2589 if (window_mode_ == POPUP) { |
2585 context_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY); | 2590 context_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY); |
2586 } else { | 2591 } else { |
2587 context_menu_contents_->AddItemWithStringId(IDS_UNDO, IDS_UNDO); | 2592 context_menu_contents_->AddItemWithStringId(IDS_UNDO, IDS_UNDO); |
2588 context_menu_contents_->AddSeparator(); | 2593 context_menu_contents_->AddSeparator(); |
2589 context_menu_contents_->AddItemWithStringId(IDC_CUT, IDS_CUT); | 2594 context_menu_contents_->AddItemWithStringId(IDC_CUT, IDS_CUT); |
2590 context_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY); | 2595 context_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY); |
2591 context_menu_contents_->AddItemWithStringId(IDC_PASTE, IDS_PASTE); | 2596 context_menu_contents_->AddItemWithStringId(IDC_PASTE, IDS_PASTE); |
2592 // GetContextualLabel() will override this next label with the | 2597 // GetContextualLabel() will override this next label with the |
2593 // IDS_PASTE_AND_SEARCH label as needed. | 2598 // IDS_PASTE_AND_SEARCH label as needed. |
2594 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO, | 2599 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2632 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2637 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
2633 } | 2638 } |
2634 | 2639 |
2635 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2640 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
2636 // Use font_.GetStringWidth() instead of | 2641 // Use font_.GetStringWidth() instead of |
2637 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2642 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
2638 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2643 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
2639 // PosFromChar(i) might return 0 when i is greater than 1. | 2644 // PosFromChar(i) might return 0 when i is greater than 1. |
2640 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2645 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2641 } | 2646 } |
OLD | NEW |