| 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_popup_contents_view.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
| 47 // OmniboxPopupContentsView, public: | 47 // OmniboxPopupContentsView, public: |
| 48 | 48 |
| 49 OmniboxPopupView* OmniboxPopupContentsView::Create( | 49 OmniboxPopupView* OmniboxPopupContentsView::Create( |
| 50 const gfx::FontList& font_list, | 50 const gfx::FontList& font_list, |
| 51 OmniboxView* omnibox_view, | 51 OmniboxView* omnibox_view, |
| 52 OmniboxEditModel* edit_model, | 52 OmniboxEditModel* edit_model, |
| 53 LocationBarView* location_bar_view) { | 53 LocationBarView* location_bar_view) { |
| 54 OmniboxPopupContentsView* view = NULL; | 54 OmniboxPopupContentsView* view = nullptr; |
| 55 view = new OmniboxPopupContentsView( | 55 view = new OmniboxPopupContentsView( |
| 56 font_list, omnibox_view, edit_model, location_bar_view); | 56 font_list, omnibox_view, edit_model, location_bar_view); |
| 57 view->Init(); | 57 view->Init(); |
| 58 return view; | 58 return view; |
| 59 } | 59 } |
| 60 | 60 |
| 61 OmniboxPopupContentsView::OmniboxPopupContentsView( | 61 OmniboxPopupContentsView::OmniboxPopupContentsView( |
| 62 const gfx::FontList& font_list, | 62 const gfx::FontList& font_list, |
| 63 OmniboxView* omnibox_view, | 63 OmniboxView* omnibox_view, |
| 64 OmniboxEditModel* edit_model, | 64 OmniboxEditModel* edit_model, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 v->GetPreferredSize().height()); | 134 v->GetPreferredSize().height()); |
| 135 top = v->bounds().bottom(); | 135 top = v->bounds().bottom(); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 //////////////////////////////////////////////////////////////////////////////// | 140 //////////////////////////////////////////////////////////////////////////////// |
| 141 // OmniboxPopupContentsView, OmniboxPopupView overrides: | 141 // OmniboxPopupContentsView, OmniboxPopupView overrides: |
| 142 | 142 |
| 143 bool OmniboxPopupContentsView::IsOpen() const { | 143 bool OmniboxPopupContentsView::IsOpen() const { |
| 144 return popup_ != NULL; | 144 return popup_ != nullptr; |
| 145 } | 145 } |
| 146 | 146 |
| 147 void OmniboxPopupContentsView::InvalidateLine(size_t line) { | 147 void OmniboxPopupContentsView::InvalidateLine(size_t line) { |
| 148 OmniboxResultView* result = result_view_at(line); | 148 OmniboxResultView* result = result_view_at(line); |
| 149 result->Invalidate(); | 149 result->Invalidate(); |
| 150 result->SchedulePaint(); | 150 result->SchedulePaint(); |
| 151 | 151 |
| 152 if (HasMatchAt(line) && GetMatchAtIndex(line).associated_keyword.get()) { | 152 if (HasMatchAt(line) && GetMatchAtIndex(line).associated_keyword.get()) { |
| 153 result->ShowKeyword(IsSelectedIndex(line) && | 153 result->ShowKeyword(IsSelectedIndex(line) && |
| 154 model_->selected_line_state() == OmniboxPopupModel::KEYWORD); | 154 model_->selected_line_state() == OmniboxPopupModel::KEYWORD); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 void OmniboxPopupContentsView::OnLineSelected(size_t line) { | 158 void OmniboxPopupContentsView::OnLineSelected(size_t line) { |
| 159 result_view_at(line)->OnSelected(); | 159 result_view_at(line)->OnSelected(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void OmniboxPopupContentsView::UpdatePopupAppearance() { | 162 void OmniboxPopupContentsView::UpdatePopupAppearance() { |
| 163 if (model_->result().empty() || omnibox_view_->IsImeShowingPopup()) { | 163 if (model_->result().empty() || omnibox_view_->IsImeShowingPopup()) { |
| 164 // No matches or the IME is showing a popup window which may overlap | 164 // No matches or the IME is showing a popup window which may overlap |
| 165 // the omnibox popup window. Close any existing popup. | 165 // the omnibox popup window. Close any existing popup. |
| 166 if (popup_ != NULL) { | 166 if (popup_) { |
| 167 size_animation_.Stop(); | 167 size_animation_.Stop(); |
| 168 | 168 |
| 169 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack | 169 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack |
| 170 // triggered by the popup receiving a message (e.g. LBUTTONUP), and | 170 // triggered by the popup receiving a message (e.g. LBUTTONUP), and |
| 171 // destroying the popup would cause us to read garbage when we unwind back | 171 // destroying the popup would cause us to read garbage when we unwind back |
| 172 // to that level. | 172 // to that level. |
| 173 popup_->Close(); // This will eventually delete the popup. | 173 popup_->Close(); // This will eventually delete the popup. |
| 174 popup_.reset(); | 174 popup_.reset(); |
| 175 } | 175 } |
| 176 return; | 176 return; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 gfx::Size(width, CalculatePopupHeight())); | 226 gfx::Size(width, CalculatePopupHeight())); |
| 227 | 227 |
| 228 // If we're animating and our target height changes, reset the animation. | 228 // If we're animating and our target height changes, reset the animation. |
| 229 // NOTE: If we just reset blindly on _every_ update, then when the user types | 229 // NOTE: If we just reset blindly on _every_ update, then when the user types |
| 230 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the | 230 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the |
| 231 // last few pixels to get to one visible result. | 231 // last few pixels to get to one visible result. |
| 232 if (new_target_bounds.height() != target_bounds_.height()) | 232 if (new_target_bounds.height() != target_bounds_.height()) |
| 233 size_animation_.Reset(); | 233 size_animation_.Reset(); |
| 234 target_bounds_ = new_target_bounds; | 234 target_bounds_ = new_target_bounds; |
| 235 | 235 |
| 236 if (popup_ == NULL) { | 236 if (!popup_) { |
| 237 views::Widget* popup_parent = location_bar_view_->GetWidget(); | 237 views::Widget* popup_parent = location_bar_view_->GetWidget(); |
| 238 | 238 |
| 239 // If the popup is currently closed, we need to create it. | 239 // If the popup is currently closed, we need to create it. |
| 240 popup_ = (new AutocompletePopupWidget(popup_parent))->AsWeakPtr(); | 240 popup_ = (new AutocompletePopupWidget(popup_parent))->AsWeakPtr(); |
| 241 | 241 |
| 242 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 242 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 243 #if defined(OS_WIN) | 243 #if defined(OS_WIN) |
| 244 // On Windows use the software compositor to ensure that we don't block | 244 // On Windows use the software compositor to ensure that we don't block |
| 245 // the UI thread blocking issue during command buffer creation. We can | 245 // the UI thread blocking issue during command buffer creation. We can |
| 246 // revert this change once http://crbug.com/125248 is fixed. | 246 // revert this change once http://crbug.com/125248 is fixed. |
| 247 params.force_software_compositing = true; | 247 params.force_software_compositing = true; |
| 248 #endif | 248 #endif |
| 249 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 249 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 250 params.parent = popup_parent->GetNativeView(); | 250 params.parent = popup_parent->GetNativeView(); |
| 251 params.bounds = GetPopupBounds(); | 251 params.bounds = GetPopupBounds(); |
| 252 params.context = popup_parent->GetNativeWindow(); | 252 params.context = popup_parent->GetNativeWindow(); |
| 253 popup_->Init(params); | 253 popup_->Init(params); |
| 254 // Third-party software such as DigitalPersona identity verification can | 254 // Third-party software such as DigitalPersona identity verification can |
| 255 // hook the underlying window creation methods and use SendMessage to | 255 // hook the underlying window creation methods and use SendMessage to |
| 256 // synchronously change focus/activation, resulting in the popup being | 256 // synchronously change focus/activation, resulting in the popup being |
| 257 // destroyed by the time control returns here. Bail out in this case to | 257 // destroyed by the time control returns here. Bail out in this case to |
| 258 // avoid a NULL dereference. | 258 // avoid a NULL dereference. |
| 259 if (!popup_.get()) | 259 if (!popup_) |
| 260 return; | 260 return; |
| 261 popup_->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); | 261 popup_->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); |
| 262 popup_->SetContentsView(this); | 262 popup_->SetContentsView(this); |
| 263 popup_->StackAbove(omnibox_view_->GetRelativeWindowForPopup()); | 263 popup_->StackAbove(omnibox_view_->GetRelativeWindowForPopup()); |
| 264 if (!popup_.get()) { | 264 if (!popup_) { |
| 265 // For some IMEs GetRelativeWindowForPopup triggers the omnibox to lose | 265 // For some IMEs GetRelativeWindowForPopup triggers the omnibox to lose |
| 266 // focus, thereby closing (and destroying) the popup. | 266 // focus, thereby closing (and destroying) the popup. |
| 267 // TODO(sky): this won't be needed once we close the omnibox on input | 267 // TODO(sky): this won't be needed once we close the omnibox on input |
| 268 // window showing. | 268 // window showing. |
| 269 return; | 269 return; |
| 270 } | 270 } |
| 271 popup_->ShowInactive(); | 271 popup_->ShowInactive(); |
| 272 } else { | 272 } else { |
| 273 // Animate the popup shrinking, but don't animate growing larger since that | 273 // Animate the popup shrinking, but don't animate growing larger since that |
| 274 // would make the popup feel less responsive. | 274 // would make the popup feel less responsive. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 const AutocompleteMatch& match) const { | 317 const AutocompleteMatch& match) const { |
| 318 return model_->IsStarredMatch(match); | 318 return model_->IsStarredMatch(match); |
| 319 } | 319 } |
| 320 | 320 |
| 321 //////////////////////////////////////////////////////////////////////////////// | 321 //////////////////////////////////////////////////////////////////////////////// |
| 322 // OmniboxPopupContentsView, AnimationDelegate implementation: | 322 // OmniboxPopupContentsView, AnimationDelegate implementation: |
| 323 | 323 |
| 324 void OmniboxPopupContentsView::AnimationProgressed( | 324 void OmniboxPopupContentsView::AnimationProgressed( |
| 325 const gfx::Animation* animation) { | 325 const gfx::Animation* animation) { |
| 326 // We should only be running the animation when the popup is already visible. | 326 // We should only be running the animation when the popup is already visible. |
| 327 DCHECK(popup_ != NULL); | 327 DCHECK(popup_); |
| 328 popup_->SetBounds(GetPopupBounds()); | 328 popup_->SetBounds(GetPopupBounds()); |
| 329 } | 329 } |
| 330 | 330 |
| 331 //////////////////////////////////////////////////////////////////////////////// | 331 //////////////////////////////////////////////////////////////////////////////// |
| 332 // OmniboxPopupContentsView, views::View overrides: | 332 // OmniboxPopupContentsView, views::View overrides: |
| 333 | 333 |
| 334 void OmniboxPopupContentsView::Layout() { | 334 void OmniboxPopupContentsView::Layout() { |
| 335 // Size our children to the available content area. | 335 // Size our children to the available content area. |
| 336 LayoutChildren(); | 336 LayoutChildren(); |
| 337 | 337 |
| 338 // We need to manually schedule a paint here since we are a layered window and | 338 // We need to manually schedule a paint here since we are a layered window and |
| 339 // won't implicitly require painting until we ask for one. | 339 // won't implicitly require painting until we ask for one. |
| 340 SchedulePaint(); | 340 SchedulePaint(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 views::View* OmniboxPopupContentsView::GetTooltipHandlerForPoint( | 343 views::View* OmniboxPopupContentsView::GetTooltipHandlerForPoint( |
| 344 const gfx::Point& point) { | 344 const gfx::Point& point) { |
| 345 return NULL; | 345 return nullptr; |
| 346 } | 346 } |
| 347 | 347 |
| 348 bool OmniboxPopupContentsView::OnMousePressed( | 348 bool OmniboxPopupContentsView::OnMousePressed( |
| 349 const ui::MouseEvent& event) { | 349 const ui::MouseEvent& event) { |
| 350 ignore_mouse_drag_ = false; // See comment on |ignore_mouse_drag_| in header. | 350 ignore_mouse_drag_ = false; // See comment on |ignore_mouse_drag_| in header. |
| 351 if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) | 351 if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) |
| 352 UpdateLineEvent(event, event.IsLeftMouseButton()); | 352 UpdateLineEvent(event, event.IsLeftMouseButton()); |
| 353 return true; | 353 return true; |
| 354 } | 354 } |
| 355 | 355 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 size_t index = GetIndexForPoint(event.location()); | 524 size_t index = GetIndexForPoint(event.location()); |
| 525 if (!HasMatchAt(index)) | 525 if (!HasMatchAt(index)) |
| 526 return; | 526 return; |
| 527 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, | 527 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, |
| 528 GURL(), base::string16(), index); | 528 GURL(), base::string16(), index); |
| 529 } | 529 } |
| 530 | 530 |
| 531 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { | 531 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { |
| 532 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); | 532 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); |
| 533 } | 533 } |
| OLD | NEW |