OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/find_in_page_view.h" | 5 #include "chrome/browser/find_in_page_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/app/theme/theme_resources.h" | 10 #include "chrome/app/theme/theme_resources.h" |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 kAnimatingEdgeHeight); | 329 kAnimatingEdgeHeight); |
330 canvas->TileImageInt(*bg_right, | 330 canvas->TileImageInt(*bg_right, |
331 lb.BottomRight().x - bg_right->width(), | 331 lb.BottomRight().x - bg_right->width(), |
332 animation_offset_, | 332 animation_offset_, |
333 bg_right->width(), | 333 bg_right->width(), |
334 kAnimatingEdgeHeight); | 334 kAnimatingEdgeHeight); |
335 } | 335 } |
336 } | 336 } |
337 | 337 |
338 void FindInPageView::Layout() { | 338 void FindInPageView::Layout() { |
339 CSize panel_size, sz; | 339 gfx::Size panel_size = GetPreferredSize(); |
340 GetPreferredSize(&panel_size); | |
341 | 340 |
342 // First we draw the close button on the far right. | 341 // First we draw the close button on the far right. |
343 close_button_->GetPreferredSize(&sz); | 342 gfx::Size sz = close_button_->GetPreferredSize(); |
344 close_button_->SetBounds(panel_size.cx - sz.cx - kMarginRightOfCloseButton, | 343 close_button_->SetBounds(panel_size.width() - sz.width() - |
345 (height() - sz.cy) / 2, | 344 kMarginRightOfCloseButton, |
346 sz.cx, | 345 (height() - sz.height()) / 2, |
347 sz.cy); | 346 sz.width(), |
| 347 sz.height()); |
348 close_button_->SetListener(this, CLOSE_TAG); | 348 close_button_->SetListener(this, CLOSE_TAG); |
349 | 349 |
350 // Next, the FindNext button to the left the close button. | 350 // Next, the FindNext button to the left the close button. |
351 find_next_button_->GetPreferredSize(&sz); | 351 sz = find_next_button_->GetPreferredSize(); |
352 find_next_button_->SetBounds(close_button_->x() - | 352 find_next_button_->SetBounds(close_button_->x() - |
353 find_next_button_->width() - | 353 find_next_button_->width() - |
354 kMarginLeftOfCloseButton, | 354 kMarginLeftOfCloseButton, |
355 (height() - sz.cy) / 2, | 355 (height() - sz.height()) / 2, |
356 sz.cx, | 356 sz.width(), |
357 sz.cy); | 357 sz.height()); |
358 find_next_button_->SetListener(this, FIND_NEXT_TAG); | 358 find_next_button_->SetListener(this, FIND_NEXT_TAG); |
359 | 359 |
360 // Then, the FindPrevious button to the left the FindNext button. | 360 // Then, the FindPrevious button to the left the FindNext button. |
361 find_previous_button_->GetPreferredSize(&sz); | 361 sz = find_previous_button_->GetPreferredSize(); |
362 find_previous_button_->SetBounds(find_next_button_->x() - | 362 find_previous_button_->SetBounds(find_next_button_->x() - |
363 find_previous_button_->width(), | 363 find_previous_button_->width(), |
364 (height() - sz.cy) / 2, | 364 (height() - sz.height()) / 2, |
365 sz.cx, | 365 sz.width(), |
366 sz.cy); | 366 sz.height()); |
367 find_previous_button_->SetListener(this, FIND_PREVIOUS_TAG); | 367 find_previous_button_->SetListener(this, FIND_PREVIOUS_TAG); |
368 | 368 |
369 // Then the label showing the match count number. | 369 // Then the label showing the match count number. |
370 match_count_text_->GetPreferredSize(&sz); | 370 sz = match_count_text_->GetPreferredSize(); |
371 // We extend the label bounds a bit to give the background highlighting a bit | 371 // We extend the label bounds a bit to give the background highlighting a bit |
372 // of breathing room (margins around the text). | 372 // of breathing room (margins around the text). |
373 sz.cx += kMatchCountExtraWidth; | 373 sz.Enlarge(kMatchCountExtraWidth, 0); |
374 sz.cx = std::max(kMatchCountMinWidth, static_cast<int>(sz.cx)); | 374 sz.set_width(std::max(kMatchCountMinWidth, static_cast<int>(sz.width()))); |
375 match_count_text_->SetBounds(find_previous_button_->x() - | 375 match_count_text_->SetBounds(find_previous_button_->x() - |
376 kWhiteSpaceAfterMatchCountLabel - | 376 kWhiteSpaceAfterMatchCountLabel - |
377 sz.cx, | 377 sz.width(), |
378 (height() - sz.cy) / 2 + 1, | 378 (height() - sz.height()) / 2 + 1, |
379 sz.cx, | 379 sz.width(), |
380 sz.cy); | 380 sz.height()); |
381 | 381 |
382 // And whatever space is left in between, gets filled up by the find edit box. | 382 // And whatever space is left in between, gets filled up by the find edit box. |
383 find_text_->GetPreferredSize(&sz); | 383 sz = find_text_->GetPreferredSize(); |
384 sz.cx = match_count_text_->x() - kMarginLeftOfFindTextField; | 384 sz.set_width(match_count_text_->x() - kMarginLeftOfFindTextField); |
385 find_text_->SetBounds(match_count_text_->x() - sz.cx, | 385 find_text_->SetBounds(match_count_text_->x() - sz.width(), |
386 (height() - sz.cy) / 2 + 1, | 386 (height() - sz.height()) / 2 + 1, |
387 sz.cx, | 387 sz.width(), |
388 sz.cy); | 388 sz.height()); |
389 find_text_->SetController(this); | 389 find_text_->SetController(this); |
390 find_text_->RequestFocus(); | 390 find_text_->RequestFocus(); |
391 | 391 |
392 // The focus forwarder view is a hidden view that should cover the area | 392 // The focus forwarder view is a hidden view that should cover the area |
393 // between the find text box and the find button so that when the user clicks | 393 // between the find text box and the find button so that when the user clicks |
394 // in that area we focus on the find text box. | 394 // in that area we focus on the find text box. |
395 int find_text_edge = find_text_->x() + find_text_->width(); | 395 int find_text_edge = find_text_->x() + find_text_->width(); |
396 focus_forwarder_view_->SetBounds(find_text_edge, | 396 focus_forwarder_view_->SetBounds(find_text_edge, |
397 find_previous_button_->y(), | 397 find_previous_button_->y(), |
398 find_previous_button_->x() - | 398 find_previous_button_->x() - |
399 find_text_edge, | 399 find_text_edge, |
400 find_previous_button_->height()); | 400 find_previous_button_->height()); |
401 } | 401 } |
402 | 402 |
403 void FindInPageView::DidChangeBounds(const CRect& old_bounds, | 403 void FindInPageView::DidChangeBounds(const CRect& old_bounds, |
404 const CRect& new_bounds) { | 404 const CRect& new_bounds) { |
405 Layout(); | 405 Layout(); |
406 } | 406 } |
407 | 407 |
408 void FindInPageView::ViewHierarchyChanged(bool is_add, | 408 void FindInPageView::ViewHierarchyChanged(bool is_add, |
409 View *parent, | 409 View *parent, |
410 View *child) { | 410 View *child) { |
411 if (is_add && child == this) { | 411 if (is_add && child == this) { |
412 find_text_->SetHorizontalMargins(3, 3); // Left and Right margins. | 412 find_text_->SetHorizontalMargins(3, 3); // Left and Right margins. |
413 find_text_->RemoveBorder(); // We draw our own border (a background image). | 413 find_text_->RemoveBorder(); // We draw our own border (a background image). |
414 } | 414 } |
415 } | 415 } |
416 | 416 |
417 void FindInPageView::GetPreferredSize(CSize* out) { | 417 gfx::Size FindInPageView::GetPreferredSize() { |
418 DCHECK(out); | 418 gfx::Size prefsize = find_text_->GetPreferredSize(); |
419 | 419 prefsize.set_height(kDlgBackground_middle->height()); |
420 find_text_->GetPreferredSize(out); | |
421 out->cy = kDlgBackground_middle->height(); | |
422 | 420 |
423 // Add up all the preferred sizes and margins of the rest of the controls. | 421 // Add up all the preferred sizes and margins of the rest of the controls. |
424 out->cx += kMarginLeftOfCloseButton + kMarginRightOfCloseButton + | 422 prefsize.Enlarge(kMarginLeftOfCloseButton + kMarginRightOfCloseButton + |
425 kMarginLeftOfFindTextField; | 423 kMarginLeftOfFindTextField, |
426 CSize sz; | 424 0); |
427 find_previous_button_->GetPreferredSize(&sz); | 425 prefsize.Enlarge(find_previous_button_->GetPreferredSize().width(), 0); |
428 out->cx += sz.cx; | 426 prefsize.Enlarge(find_next_button_->GetPreferredSize().width(), 0); |
429 find_next_button_->GetPreferredSize(&sz); | 427 prefsize.Enlarge(close_button_->GetPreferredSize().width(), 0); |
430 out->cx += sz.cx; | 428 return prefsize; |
431 close_button_->GetPreferredSize(&sz); | |
432 out->cx += sz.cx; | |
433 } | 429 } |
434 | 430 |
435 //////////////////////////////////////////////////////////////////////////////// | 431 //////////////////////////////////////////////////////////////////////////////// |
436 // FindInPageView, ChromeViews::BaseButton::ButtonListener implementation: | 432 // FindInPageView, ChromeViews::BaseButton::ButtonListener implementation: |
437 | 433 |
438 void FindInPageView::ButtonPressed(ChromeViews::BaseButton* sender) { | 434 void FindInPageView::ButtonPressed(ChromeViews::BaseButton* sender) { |
439 switch (sender->GetTag()) { | 435 switch (sender->GetTag()) { |
440 case FIND_PREVIOUS_TAG: | 436 case FIND_PREVIOUS_TAG: |
441 case FIND_NEXT_TAG: | 437 case FIND_NEXT_TAG: |
442 if (find_text_->GetText().length() > 0) { | 438 if (find_text_->GetText().length() > 0) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 | 492 |
497 bool FindInPageView::FocusForwarderView::OnMousePressed( | 493 bool FindInPageView::FocusForwarderView::OnMousePressed( |
498 const ChromeViews::MouseEvent& event) { | 494 const ChromeViews::MouseEvent& event) { |
499 if (view_to_focus_on_mousedown_) { | 495 if (view_to_focus_on_mousedown_) { |
500 view_to_focus_on_mousedown_->ClearSelection(); | 496 view_to_focus_on_mousedown_->ClearSelection(); |
501 view_to_focus_on_mousedown_->RequestFocus(); | 497 view_to_focus_on_mousedown_->RequestFocus(); |
502 } | 498 } |
503 return true; | 499 return true; |
504 } | 500 } |
505 | 501 |
OLD | NEW |