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

Side by Side Diff: chrome/browser/views/location_bar_view.cc

Issue 155789: Fix RTL: Omnibar - message "Press Tab to search Google" doesn't show correctly in a "New (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months 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
« no previous file with comments | « chrome/browser/views/location_bar_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/views/location_bar_view.h" 5 #include "chrome/browser/views/location_bar_view.h"
6 6
7 #if defined(OS_LINUX) 7 #if defined(OS_LINUX)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 RECT edit_bounds; 413 RECT edit_bounds;
414 location_entry_->GetClientRect(&edit_bounds); 414 location_entry_->GetClientRect(&edit_bounds);
415 int max_edit_width = entry_width - formatting_rect.left - 415 int max_edit_width = entry_width - formatting_rect.left -
416 (edit_bounds.right - formatting_rect.right); 416 (edit_bounds.right - formatting_rect.right);
417 #else 417 #else
418 int max_edit_width = entry_width; 418 int max_edit_width = entry_width;
419 #endif 419 #endif
420 420
421 if (max_edit_width < 0) 421 if (max_edit_width < 0)
422 return; 422 return;
423 const int text_width = TextDisplayWidth(); 423 const int available_width = AvailableWidth(max_edit_width);
424 bool needs_layout = force_layout; 424 bool needs_layout = force_layout;
425 needs_layout |= AdjustHints(text_width, max_edit_width); 425 needs_layout |= AdjustHints(available_width);
426 426
427 if (!needs_layout) 427 if (!needs_layout)
428 return; 428 return;
429 429
430 // TODO(sky): baseline layout. 430 // TODO(sky): baseline layout.
431 int location_y = TopMargin(); 431 int location_y = TopMargin();
432 int location_height = std::max(height() - location_y - kVertMargin, 0); 432 int location_height = std::max(height() - location_y - kVertMargin, 0);
433 433
434 // First set the bounds for the label that appears to the right of the 434 // First set the bounds for the label that appears to the right of the
435 // security icon. 435 // security icon.
(...skipping 18 matching lines...) Expand all
454 offset -= page_action_size.width(); 454 offset -= page_action_size.width();
455 page_action_image_views_[i]->SetBounds(offset, location_y, 455 page_action_image_views_[i]->SetBounds(offset, location_y,
456 page_action_size.width(), 456 page_action_size.width(),
457 location_height); 457 location_height);
458 offset -= kInnerPadding; 458 offset -= kInnerPadding;
459 } 459 }
460 } 460 }
461 gfx::Rect location_bounds(kEntryPadding, location_y, entry_width, 461 gfx::Rect location_bounds(kEntryPadding, location_y, entry_width,
462 location_height); 462 location_height);
463 if (selected_keyword_view_.IsVisible()) { 463 if (selected_keyword_view_.IsVisible()) {
464 LayoutView(true, &selected_keyword_view_, text_width, max_edit_width, 464 LayoutView(true, &selected_keyword_view_, available_width,
465 &location_bounds); 465 &location_bounds);
466 } else if (keyword_hint_view_.IsVisible()) { 466 } else if (keyword_hint_view_.IsVisible()) {
467 LayoutView(false, &keyword_hint_view_, text_width, max_edit_width, 467 LayoutView(false, &keyword_hint_view_, available_width,
468 &location_bounds); 468 &location_bounds);
469 } else if (type_to_search_view_.IsVisible()) { 469 } else if (type_to_search_view_.IsVisible()) {
470 LayoutView(false, &type_to_search_view_, text_width, max_edit_width, 470 LayoutView(false, &type_to_search_view_, available_width,
471 &location_bounds); 471 &location_bounds);
472 } 472 }
473 473
474 location_entry_view_->SetBounds(location_bounds); 474 location_entry_view_->SetBounds(location_bounds);
475 if (!force_layout) { 475 if (!force_layout) {
476 // If force_layout is false and we got this far it means one of the views 476 // If force_layout is false and we got this far it means one of the views
477 // was added/removed or changed in size. We need to paint ourselves. 477 // was added/removed or changed in size. We need to paint ourselves.
478 SchedulePaint(); 478 SchedulePaint();
479 } 479 }
480 } 480 }
481 481
482 int LocationBarView::TopMargin() const { 482 int LocationBarView::TopMargin() const {
483 return std::min(kVertMargin, height()); 483 return std::min(kVertMargin, height());
484 } 484 }
485 485
486 int LocationBarView::TextDisplayWidth() { 486 int LocationBarView::AvailableWidth(int location_bar_width) {
487 #if defined(OS_WIN) 487 #if defined(OS_WIN)
488 POINT last_char_position = 488 // Use font_.GetStringWidth() instead of
489 location_entry_->PosFromChar(location_entry_->GetTextLength()); 489 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is
490 POINT scroll_position; 490 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout,
491 location_entry_->GetScrollPos(&scroll_position); 491 // PosFromChar(i) might return 0 when i is greater than 1.
492 const int position_x = last_char_position.x + scroll_position.x; 492 return std::max(
493 return UILayoutIsRightToLeft() ? width() - position_x : position_x; 493 location_bar_width - font_.GetStringWidth(location_entry_->GetText()), 0);
494 #else 494 #else
495 NOTIMPLEMENTED(); 495 NOTIMPLEMENTED();
496 return 0; 496 return location_bar_width;
497 #endif 497 #endif
498 } 498 }
499 499
500 bool LocationBarView::UsePref(int pref_width, int text_width, int max_width) { 500 bool LocationBarView::UsePref(int pref_width, int available_width) {
501 return (pref_width + kInnerPadding + text_width <= max_width); 501 return (pref_width + kInnerPadding <= available_width);
502 } 502 }
503 503
504 bool LocationBarView::NeedsResize(View* view, int text_width, int max_width) { 504 bool LocationBarView::NeedsResize(View* view, int available_width) {
505 gfx::Size size = view->GetPreferredSize(); 505 gfx::Size size = view->GetPreferredSize();
506 if (!UsePref(size.width(), text_width, max_width)) 506 if (!UsePref(size.width(), available_width))
507 size = view->GetMinimumSize(); 507 size = view->GetMinimumSize();
508 return (view->width() != size.width()); 508 return (view->width() != size.width());
509 } 509 }
510 510
511 bool LocationBarView::AdjustHints(int text_width, int max_width) { 511 bool LocationBarView::AdjustHints(int available_width) {
512 const std::wstring keyword(location_entry_->model()->keyword()); 512 const std::wstring keyword(location_entry_->model()->keyword());
513 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); 513 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint());
514 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; 514 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint;
515 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; 515 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint;
516 bool show_search_hint(location_entry_->model()->show_search_hint()); 516 bool show_search_hint(location_entry_->model()->show_search_hint());
517 DCHECK(keyword.empty() || !show_search_hint); 517 DCHECK(keyword.empty() || !show_search_hint);
518 518
519 if (show_search_hint) { 519 if (show_search_hint) {
520 // Only show type to search if all the text fits. 520 // Only show type to search if all the text fits.
521 gfx::Size view_pref = type_to_search_view_.GetPreferredSize(); 521 gfx::Size view_pref = type_to_search_view_.GetPreferredSize();
522 show_search_hint = UsePref(view_pref.width(), text_width, max_width); 522 show_search_hint = UsePref(view_pref.width(), available_width);
523 } 523 }
524 524
525 // NOTE: This isn't just one big || statement as ToggleVisibility MUST be 525 // NOTE: This isn't just one big || statement as ToggleVisibility MUST be
526 // invoked for each view. 526 // invoked for each view.
527 bool needs_layout = false; 527 bool needs_layout = false;
528 needs_layout |= ToggleVisibility(show_selected_keyword, 528 needs_layout |= ToggleVisibility(show_selected_keyword,
529 &selected_keyword_view_); 529 &selected_keyword_view_);
530 needs_layout |= ToggleVisibility(show_keyword_hint, &keyword_hint_view_); 530 needs_layout |= ToggleVisibility(show_keyword_hint, &keyword_hint_view_);
531 needs_layout |= ToggleVisibility(show_search_hint, &type_to_search_view_); 531 needs_layout |= ToggleVisibility(show_search_hint, &type_to_search_view_);
532 if (show_selected_keyword) { 532 if (show_selected_keyword) {
533 if (selected_keyword_view_.keyword() != keyword) { 533 if (selected_keyword_view_.keyword() != keyword) {
534 needs_layout = true; 534 needs_layout = true;
535 selected_keyword_view_.SetKeyword(keyword); 535 selected_keyword_view_.SetKeyword(keyword);
536 } 536 }
537 needs_layout |= NeedsResize(&selected_keyword_view_, text_width, max_width); 537 needs_layout |= NeedsResize(&selected_keyword_view_, available_width);
538 } else if (show_keyword_hint) { 538 } else if (show_keyword_hint) {
539 if (keyword_hint_view_.keyword() != keyword) { 539 if (keyword_hint_view_.keyword() != keyword) {
540 needs_layout = true; 540 needs_layout = true;
541 keyword_hint_view_.SetKeyword(keyword); 541 keyword_hint_view_.SetKeyword(keyword);
542 } 542 }
543 needs_layout |= NeedsResize(&keyword_hint_view_, text_width, max_width); 543 needs_layout |= NeedsResize(&keyword_hint_view_, available_width);
544 } 544 }
545 545
546 return needs_layout; 546 return needs_layout;
547 } 547 }
548 548
549 void LocationBarView::LayoutView(bool leading, views::View* view, 549 void LocationBarView::LayoutView(bool leading,
550 int text_width, int max_width, 550 views::View* view,
551 int available_width,
551 gfx::Rect* bounds) { 552 gfx::Rect* bounds) {
552 DCHECK(view && bounds); 553 DCHECK(view && bounds);
553 gfx::Size view_size = view->GetPreferredSize(); 554 gfx::Size view_size = view->GetPreferredSize();
554 if (!UsePref(view_size.width(), text_width, max_width)) 555 if (!UsePref(view_size.width(), available_width))
555 view_size = view->GetMinimumSize(); 556 view_size = view->GetMinimumSize();
556 if (view_size.width() + kInnerPadding < bounds->width()) { 557 if (view_size.width() + kInnerPadding < bounds->width()) {
557 view->SetVisible(true); 558 view->SetVisible(true);
558 if (leading) { 559 if (leading) {
559 view->SetBounds(bounds->x(), bounds->y(), view_size.width(), 560 view->SetBounds(bounds->x(), bounds->y(), view_size.width(),
560 bounds->height()); 561 bounds->height());
561 bounds->Offset(view_size.width() + kInnerPadding, 0); 562 bounds->Offset(view_size.width() + kInnerPadding, 0);
562 } else { 563 } else {
563 view->SetBounds(bounds->right() - view_size.width(), bounds->y(), 564 view->SetBounds(bounds->right() - view_size.width(), bounds->y(),
564 view_size.width(), bounds->height()); 565 view_size.width(), bounds->height());
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 } 1371 }
1371 1372
1372 int LocationBarView::PageActionVisibleCount() { 1373 int LocationBarView::PageActionVisibleCount() {
1373 int result = 0; 1374 int result = 0;
1374 for (size_t i = 0; i < page_action_image_views_.size(); i++) { 1375 for (size_t i = 0; i < page_action_image_views_.size(); i++) {
1375 if (page_action_image_views_[i]->IsVisible()) 1376 if (page_action_image_views_[i]->IsVisible())
1376 ++result; 1377 ++result;
1377 } 1378 }
1378 return result; 1379 return result;
1379 } 1380 }
OLDNEW
« no previous file with comments | « chrome/browser/views/location_bar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698