Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc

Issue 11360144: Converts some of the omnibox related classes to support multiple (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unneeded include Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/ui/omnibox/omnibox_view.h" 7 #include "chrome/browser/ui/omnibox/omnibox_view.h"
8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
9 #include "chrome/browser/ui/views/omnibox/omnibox_popup_non_view.h" 9 #include "chrome/browser/ui/views/omnibox/omnibox_popup_non_view.h"
10 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" 10 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 153 }
154 154
155 //////////////////////////////////////////////////////////////////////////////// 155 ////////////////////////////////////////////////////////////////////////////////
156 // OmniboxPopupContentsView, OmniboxPopupView overrides: 156 // OmniboxPopupContentsView, OmniboxPopupView overrides:
157 157
158 bool OmniboxPopupContentsView::IsOpen() const { 158 bool OmniboxPopupContentsView::IsOpen() const {
159 return popup_ != NULL; 159 return popup_ != NULL;
160 } 160 }
161 161
162 void OmniboxPopupContentsView::InvalidateLine(size_t line) { 162 void OmniboxPopupContentsView::InvalidateLine(size_t line) {
163 OmniboxResultView* result = static_cast<OmniboxResultView*>( 163 OmniboxResultView* result = result_view_at(line);
164 child_at(static_cast<int>(line)));
165 result->Invalidate(); 164 result->Invalidate();
166 165
167 if (HasMatchAt(line) && GetMatchAtIndex(line).associated_keyword.get()) { 166 if (HasMatchAt(line) && GetMatchAtIndex(line).associated_keyword.get()) {
168 result->ShowKeyword(IsSelectedIndex(line) && 167 result->ShowKeyword(IsSelectedIndex(line) &&
169 model_->selected_line_state() == OmniboxPopupModel::KEYWORD); 168 model_->selected_line_state() == OmniboxPopupModel::KEYWORD);
170 } 169 }
171 } 170 }
172 171
173 void OmniboxPopupContentsView::UpdatePopupAppearance() { 172 void OmniboxPopupContentsView::UpdatePopupAppearance() {
174 if (model_->result().empty()) { 173 if (model_->result().empty()) {
175 // No matches, close any existing popup. 174 // No matches, close any existing popup.
176 if (popup_ != NULL) { 175 if (popup_ != NULL) {
177 size_animation_.Stop(); 176 size_animation_.Stop();
178 177
179 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack 178 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack
180 // triggered by the popup receiving a message (e.g. LBUTTONUP), and 179 // triggered by the popup receiving a message (e.g. LBUTTONUP), and
181 // destroying the popup would cause us to read garbage when we unwind back 180 // destroying the popup would cause us to read garbage when we unwind back
182 // to that level. 181 // to that level.
183 popup_->Close(); // This will eventually delete the popup. 182 popup_->Close(); // This will eventually delete the popup.
184 popup_.reset(); 183 popup_.reset();
185 } 184 }
186 return; 185 return;
187 } 186 }
188 187
189 // Update the match cached by each row, in the process of doing so make sure 188 // Update the match cached by each row, in the process of doing so make sure
190 // we have enough row views. 189 // we have enough row views.
191 size_t child_rv_count = child_count(); 190 size_t child_rv_count = child_count();
192 const size_t result_size = model_->result().size(); 191 const size_t result_size = model_->result().size();
193 for (size_t i = 0; i < result_size; ++i) { 192 for (size_t i = 0; i < result_size; ++i) {
194 OmniboxResultView* view = static_cast<OmniboxResultView*>(child_at(i)); 193 OmniboxResultView* view = result_view_at(i);
195 view->SetMatch(GetMatchAtIndex(i)); 194 view->SetMatch(GetMatchAtIndex(i));
196 view->SetVisible(true); 195 view->SetVisible(true);
197 } 196 }
198 for (size_t i = result_size; i < child_rv_count; ++i) 197 for (size_t i = result_size; i < child_rv_count; ++i)
199 child_at(i)->SetVisible(false); 198 child_at(i)->SetVisible(false);
200 199
201 gfx::Rect new_target_bounds = CalculateTargetBounds(CalculatePopupHeight()); 200 gfx::Rect new_target_bounds = CalculateTargetBounds(CalculatePopupHeight());
202 201
203 // If we're animating and our target height changes, reset the animation. 202 // If we're animating and our target height changes, reset the animation.
204 // NOTE: If we just reset blindly on _every_ update, then when the user types 203 // NOTE: If we just reset blindly on _every_ update, then when the user types
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 default: 374 default:
376 return ui::ER_UNHANDLED; 375 return ui::ER_UNHANDLED;
377 } 376 }
378 return ui::ER_CONSUMED; 377 return ui::ER_CONSUMED;
379 } 378 }
380 379
381 //////////////////////////////////////////////////////////////////////////////// 380 ////////////////////////////////////////////////////////////////////////////////
382 // OmniboxPopupContentsView, protected: 381 // OmniboxPopupContentsView, protected:
383 382
384 void OmniboxPopupContentsView::PaintResultViews(gfx::Canvas* canvas) { 383 void OmniboxPopupContentsView::PaintResultViews(gfx::Canvas* canvas) {
385 canvas->DrawColor(OmniboxResultView::GetColor( 384 canvas->DrawColor(result_view_at(0)->GetColor(
386 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND)); 385 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND));
387 View::PaintChildren(canvas); 386 View::PaintChildren(canvas);
388 } 387 }
389 388
390 int OmniboxPopupContentsView::CalculatePopupHeight() { 389 int OmniboxPopupContentsView::CalculatePopupHeight() {
391 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); 390 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size());
392 int popup_height = 0; 391 int popup_height = 0;
393 for (size_t i = 0; i < model_->result().size(); ++i) 392 for (size_t i = 0; i < model_->result().size(); ++i)
394 popup_height += child_at(i)->GetPreferredSize().height(); 393 popup_height += child_at(i)->GetPreferredSize().height();
395 return popup_height; 394 return popup_height;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 bb.hRgnBlur = popup_region.Get(); 478 bb.hRgnBlur = popup_region.Get();
480 DwmEnableBlurBehindWindow(GetWidget()->GetNativeView(), &bb); 479 DwmEnableBlurBehindWindow(GetWidget()->GetNativeView(), &bb);
481 #endif 480 #endif
482 } 481 }
483 482
484 void OmniboxPopupContentsView::MakeCanvasTransparent(gfx::Canvas* canvas) { 483 void OmniboxPopupContentsView::MakeCanvasTransparent(gfx::Canvas* canvas) {
485 // Allow the window blur effect to show through the popup background. 484 // Allow the window blur effect to show through the popup background.
486 SkAlpha alpha = GetThemeProvider()->ShouldUseNativeFrame() ? 485 SkAlpha alpha = GetThemeProvider()->ShouldUseNativeFrame() ?
487 kGlassPopupAlpha : kOpaquePopupAlpha; 486 kGlassPopupAlpha : kOpaquePopupAlpha;
488 canvas->DrawColor(SkColorSetA( 487 canvas->DrawColor(SkColorSetA(
489 OmniboxResultView::GetColor(OmniboxResultView::NORMAL, 488 result_view_at(0)->GetColor(OmniboxResultView::NORMAL,
490 OmniboxResultView::BACKGROUND), alpha), SkXfermode::kDstIn_Mode); 489 OmniboxResultView::BACKGROUND), alpha), SkXfermode::kDstIn_Mode);
491 } 490 }
492 491
493 void OmniboxPopupContentsView::OpenIndex(size_t index, 492 void OmniboxPopupContentsView::OpenIndex(size_t index,
494 WindowOpenDisposition disposition) { 493 WindowOpenDisposition disposition) {
495 if (!HasMatchAt(index)) 494 if (!HasMatchAt(index))
496 return; 495 return;
497 496
498 // OpenMatch() may close the popup, which will clear the result set and, by 497 // OpenMatch() may close the popup, which will clear the result set and, by
499 // extension, |match| and its contents. So copy the relevant match out to 498 // extension, |match| and its contents. So copy the relevant match out to
(...skipping 12 matching lines...) Expand all
512 for (int i = 0; i < nb_match; ++i) { 511 for (int i = 0; i < nb_match; ++i) {
513 views::View* child = child_at(i); 512 views::View* child = child_at(i);
514 gfx::Point point_in_child_coords(point); 513 gfx::Point point_in_child_coords(point);
515 View::ConvertPointToTarget(this, child, &point_in_child_coords); 514 View::ConvertPointToTarget(this, child, &point_in_child_coords);
516 if (child->HitTestPoint(point_in_child_coords)) 515 if (child->HitTestPoint(point_in_child_coords))
517 return i; 516 return i;
518 } 517 }
519 return OmniboxPopupModel::kNoMatch; 518 return OmniboxPopupModel::kNoMatch;
520 } 519 }
521 520
522 gfx::Rect OmniboxPopupContentsView::CalculateTargetBounds(int h) { 521 gfx::Rect OmniboxPopupContentsView::CalculateTargetBounds(int h) {
Peter Kasting 2012/11/09 21:21:11 Nit: While here, move this function to where it is
523 gfx::Rect location_bar_bounds(location_bar_->GetContentsBounds()); 522 gfx::Rect location_bar_bounds(location_bar_->GetContentsBounds());
524 const views::Border* border = location_bar_->border(); 523 const views::Border* border = location_bar_->border();
525 if (border) { 524 if (border) {
526 // Adjust for the border so that the bubble and location bar borders are 525 // Adjust for the border so that the bubble and location bar borders are
527 // aligned. 526 // aligned.
528 gfx::Insets insets; 527 gfx::Insets insets;
529 border->GetInsets(&insets); 528 border->GetInsets(&insets);
530 location_bar_bounds.Inset(insets.left(), 0, insets.right(), 0); 529 location_bar_bounds.Inset(insets.left(), 0, insets.right(), 0);
531 } else { 530 } else {
532 // The normal location bar is drawn using a background graphic that includes 531 // The normal location bar is drawn using a background graphic that includes
(...skipping 17 matching lines...) Expand all
550 if (HasMatchAt(index) && should_set_selected_line) 549 if (HasMatchAt(index) && should_set_selected_line)
551 model_->SetSelectedLine(index, false, false); 550 model_->SetSelectedLine(index, false, false);
552 } 551 }
553 552
554 void OmniboxPopupContentsView::OpenSelectedLine( 553 void OmniboxPopupContentsView::OpenSelectedLine(
555 const ui::LocatedEvent& event, 554 const ui::LocatedEvent& event,
556 WindowOpenDisposition disposition) { 555 WindowOpenDisposition disposition) {
557 size_t index = GetIndexForPoint(event.location()); 556 size_t index = GetIndexForPoint(event.location());
558 OpenIndex(index, disposition); 557 OpenIndex(index, disposition);
559 } 558 }
559
560 OmniboxResultView* OmniboxPopupContentsView::result_view_at(int i) {
Peter Kasting 2012/11/09 21:21:11 Nit: Callers pass a size_t, maybe this should take
sky 2012/11/09 21:28:55 Done.
561 return static_cast<OmniboxResultView*>(child_at(i));
562 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h ('k') | chrome/browser/ui/views/omnibox/omnibox_result_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698