| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/views/autocomplete/autocomplete_popup_win.h" | 5 #include "chrome/browser/views/autocomplete/autocomplete_popup_win.h" |
| 6 | 6 |
| 7 #include "app/gfx/insets.h" | 7 #include "app/gfx/insets.h" |
| 8 #include "app/win_util.h" | 8 #include "app/win_util.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h" | 9 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 10 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 11 #include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h" | 11 #include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h" |
| 12 | 12 |
| 13 //////////////////////////////////////////////////////////////////////////////// | 13 //////////////////////////////////////////////////////////////////////////////// |
| 14 // AutocompletePopupWin, public: | 14 // AutocompletePopupWin, public: |
| 15 | 15 |
| 16 AutocompletePopupWin::AutocompletePopupWin( | 16 AutocompletePopupWin::AutocompletePopupWin( |
| 17 AutocompletePopupContentsView* contents) | 17 AutocompleteEditView* edit_view, |
| 18 : contents_(contents), | 18 AutocompletePopupContentsView* contents) { |
| 19 is_open_(false) { | 19 // Create the popup. |
| 20 set_delete_on_destroy(false); | 20 set_delete_on_destroy(false); // Owned by |contents|. |
| 21 set_window_style(WS_POPUP | WS_CLIPCHILDREN); | 21 set_window_style(WS_POPUP | WS_CLIPCHILDREN); |
| 22 set_window_ex_style(WS_EX_TOOLWINDOW | WS_EX_LAYERED); | 22 set_window_ex_style(WS_EX_TOOLWINDOW | WS_EX_LAYERED); |
| 23 } | |
| 24 | |
| 25 AutocompletePopupWin::~AutocompletePopupWin() { | |
| 26 } | |
| 27 | |
| 28 void AutocompletePopupWin::Show() { | |
| 29 // Move the popup to the place appropriate for the window's current position - | |
| 30 // it may have been moved since it was last shown. | |
| 31 SetBounds(contents_->GetPopupBounds()); | |
| 32 if (!IsVisible()) | |
| 33 WidgetWin::Show(); | |
| 34 is_open_ = true; | |
| 35 } | |
| 36 | |
| 37 void AutocompletePopupWin::Hide() { | |
| 38 WidgetWin::Hide(); | |
| 39 is_open_ = false; | |
| 40 } | |
| 41 | |
| 42 void AutocompletePopupWin::Init(AutocompleteEditView* edit_view, | |
| 43 views::View* contents) { | |
| 44 // Create the popup | |
| 45 WidgetWin::Init(GetAncestor(edit_view->GetNativeView(), GA_ROOT), | 23 WidgetWin::Init(GetAncestor(edit_view->GetNativeView(), GA_ROOT), |
| 46 contents_->GetPopupBounds()); | 24 contents->GetPopupBounds()); |
| 47 // The contents is owned by the LocationBarView. | 25 // The contents is owned by the LocationBarView. |
| 48 contents_->set_parent_owned(false); | 26 contents->set_parent_owned(false); |
| 49 SetContentsView(contents_); | 27 SetContentsView(contents); |
| 50 | 28 |
| 51 // When an IME is attached to the rich-edit control, retrieve its window | 29 // When an IME is attached to the rich-edit control, retrieve its window |
| 52 // handle and show this popup window under the IME windows. | 30 // handle and show this popup window under the IME windows. |
| 53 // Otherwise, show this popup window under top-most windows. | 31 // Otherwise, show this popup window under top-most windows. |
| 54 // TODO(hbono): http://b/1111369 if we exclude this popup window from the | 32 // TODO(hbono): http://b/1111369 if we exclude this popup window from the |
| 55 // display area of IME windows, this workaround becomes unnecessary. | 33 // display area of IME windows, this workaround becomes unnecessary. |
| 56 HWND ime_window = ImmGetDefaultIMEWnd(edit_view->GetNativeView()); | 34 HWND ime_window = ImmGetDefaultIMEWnd(edit_view->GetNativeView()); |
| 57 SetWindowPos(ime_window ? ime_window : HWND_NOTOPMOST, 0, 0, 0, 0, | 35 SetWindowPos(ime_window ? ime_window : HWND_NOTOPMOST, 0, 0, 0, 0, |
| 58 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW); | 36 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW); |
| 59 is_open_ = true; | |
| 60 } | 37 } |
| 61 | 38 |
| 62 bool AutocompletePopupWin::IsOpen() const { | 39 AutocompletePopupWin::~AutocompletePopupWin() { |
| 63 const bool is_open = IsCreated() && IsVisible(); | |
| 64 CHECK(is_open == is_open_); | |
| 65 return is_open; | |
| 66 } | |
| 67 | |
| 68 bool AutocompletePopupWin::IsCreated() const { | |
| 69 return !!IsWindow(); | |
| 70 } | 40 } |
| 71 | 41 |
| 72 //////////////////////////////////////////////////////////////////////////////// | 42 //////////////////////////////////////////////////////////////////////////////// |
| 73 // AutocompletePopupWin, WidgetWin overrides: | 43 // AutocompletePopupWin, WidgetWin overrides: |
| 74 | 44 |
| 75 LRESULT AutocompletePopupWin::OnMouseActivate(HWND window, UINT hit_test, | 45 LRESULT AutocompletePopupWin::OnMouseActivate(HWND window, UINT hit_test, |
| 76 UINT mouse_message) { | 46 UINT mouse_message) { |
| 77 return MA_NOACTIVATE; | 47 return MA_NOACTIVATE; |
| 78 } | 48 } |
| OLD | NEW |