| 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/views/location_bar_view.h" | 5 #include "chrome/browser/views/location_bar_view.h" |
| 6 | 6 |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/app/chrome_dll_resource.h" | 9 #include "chrome/app/chrome_dll_resource.h" |
| 10 #include "chrome/app/theme/theme_resources.h" | 10 #include "chrome/app/theme/theme_resources.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "chrome/common/gfx/chrome_canvas.h" | 26 #include "chrome/common/gfx/chrome_canvas.h" |
| 27 #include "chrome/common/win_util.h" | 27 #include "chrome/common/win_util.h" |
| 28 #include "chrome/views/background.h" | 28 #include "chrome/views/background.h" |
| 29 #include "chrome/views/border.h" | 29 #include "chrome/views/border.h" |
| 30 #include "chrome/views/root_view.h" | 30 #include "chrome/views/root_view.h" |
| 31 #include "chrome/views/widget.h" | 31 #include "chrome/views/widget.h" |
| 32 #include "generated_resources.h" | 32 #include "generated_resources.h" |
| 33 | 33 |
| 34 using views::View; | 34 using views::View; |
| 35 | 35 |
| 36 const int LocationBarView::kTextVertMargin = 2; | 36 const int LocationBarView::kVertMargin = 2; |
| 37 | 37 |
| 38 const COLORREF LocationBarView::kBackgroundColorByLevel[] = { | 38 const COLORREF LocationBarView::kBackgroundColorByLevel[] = { |
| 39 RGB(255, 245, 195), // SecurityLevel SECURE: Yellow. | 39 RGB(255, 245, 195), // SecurityLevel SECURE: Yellow. |
| 40 RGB(255, 255, 255), // SecurityLevel NORMAL: White. | 40 RGB(255, 255, 255), // SecurityLevel NORMAL: White. |
| 41 RGB(255, 255, 255), // SecurityLevel INSECURE: White. | 41 RGB(255, 255, 255), // SecurityLevel INSECURE: White. |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 // The margins around the solid color we draw. | |
| 45 static const int kBackgroundVertMargin = 2; | |
| 46 static const int kBackgroundHoriMargin = 0; | |
| 47 | |
| 48 // Padding on the right and left of the entry field. | 44 // Padding on the right and left of the entry field. |
| 49 static const int kEntryPadding = 3; | 45 static const int kEntryPadding = 3; |
| 50 | 46 |
| 51 // Padding between the entry and the leading/trailing views. | 47 // Padding between the entry and the leading/trailing views. |
| 52 static const int kInnerPadding = 3; | 48 static const int kInnerPadding = 3; |
| 53 | 49 |
| 54 static const SkBitmap* kBackground = NULL; | 50 static const SkBitmap* kBackground = NULL; |
| 55 | 51 |
| 56 static const SkBitmap* kPopupBackground = NULL; | 52 static const SkBitmap* kPopupBackground = NULL; |
| 57 static const int kPopupBackgroundVertMargin = 2; | |
| 58 | 53 |
| 59 // The delay the mouse has to be hovering over the lock/warning icon before the | 54 // The delay the mouse has to be hovering over the lock/warning icon before the |
| 60 // info bubble is shown. | 55 // info bubble is shown. |
| 61 static const int kInfoBubbleHoverDelayMs = 500; | 56 static const int kInfoBubbleHoverDelayMs = 500; |
| 62 | 57 |
| 63 // The tab key image. | 58 // The tab key image. |
| 64 static const SkBitmap* kTabButtonBitmap = NULL; | 59 static const SkBitmap* kTabButtonBitmap = NULL; |
| 65 | 60 |
| 66 // Returns the description for a keyword. | 61 // Returns the description for a keyword. |
| 67 static std::wstring GetKeywordDescription(Profile* profile, | 62 static std::wstring GetKeywordDescription(Profile* profile, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 profile_ = profile; | 186 profile_ = profile; |
| 192 location_entry_->model()->SetProfile(profile); | 187 location_entry_->model()->SetProfile(profile); |
| 193 selected_keyword_view_.set_profile(profile); | 188 selected_keyword_view_.set_profile(profile); |
| 194 keyword_hint_view_.set_profile(profile); | 189 keyword_hint_view_.set_profile(profile); |
| 195 security_image_view_.set_profile(profile); | 190 security_image_view_.set_profile(profile); |
| 196 } | 191 } |
| 197 } | 192 } |
| 198 | 193 |
| 199 gfx::Size LocationBarView::GetPreferredSize() { | 194 gfx::Size LocationBarView::GetPreferredSize() { |
| 200 return gfx::Size(0, | 195 return gfx::Size(0, |
| 201 std::max((popup_window_mode_ ? kPopupBackground : kBackground)->height(), | 196 (popup_window_mode_ ? kPopupBackground : kBackground)->height() - |
| 202 security_image_view_.GetPreferredSize().height())); | 197 TopOffset()); |
| 203 } | 198 } |
| 204 | 199 |
| 205 void LocationBarView::Layout() { | 200 void LocationBarView::Layout() { |
| 206 DoLayout(true); | 201 DoLayout(true); |
| 207 } | 202 } |
| 208 | 203 |
| 209 void LocationBarView::Paint(ChromeCanvas* canvas) { | 204 void LocationBarView::Paint(ChromeCanvas* canvas) { |
| 210 View::Paint(canvas); | 205 View::Paint(canvas); |
| 211 | 206 |
| 212 SkColor bg = SkColorSetRGB( | 207 SkColor bg = SkColorSetRGB( |
| 213 GetRValue(kBackgroundColorByLevel[model_->GetSchemeSecurityLevel()]), | 208 GetRValue(kBackgroundColorByLevel[model_->GetSchemeSecurityLevel()]), |
| 214 GetGValue(kBackgroundColorByLevel[model_->GetSchemeSecurityLevel()]), | 209 GetGValue(kBackgroundColorByLevel[model_->GetSchemeSecurityLevel()]), |
| 215 GetBValue(kBackgroundColorByLevel[model_->GetSchemeSecurityLevel()])); | 210 GetBValue(kBackgroundColorByLevel[model_->GetSchemeSecurityLevel()])); |
| 216 | 211 |
| 217 if (popup_window_mode_) { | 212 const SkBitmap* background = |
| 218 canvas->TileImageInt(*kPopupBackground, 0, 0, width(), | 213 popup_window_mode_ ? kPopupBackground : kBackground; |
| 219 kPopupBackground->height()); | 214 int top_offset = TopOffset(); |
| 220 canvas->FillRectInt(bg, 0, kPopupBackgroundVertMargin, width(), | 215 canvas->TileImageInt(*background, 0, top_offset, 0, 0, width(), height()); |
| 221 kPopupBackground->height() - (kPopupBackgroundVertMargin * 2)); | 216 int top_margin = TopMargin(); |
| 222 } else { | 217 canvas->FillRectInt(bg, 0, top_margin, width(), |
| 223 int bh = kBackground->height(); | 218 height() - top_margin - kVertMargin); |
| 224 canvas->TileImageInt(*kBackground, 0, (height() - bh) / 2, width(), | |
| 225 bh); | |
| 226 canvas->FillRectInt(bg, kBackgroundHoriMargin, kBackgroundVertMargin, | |
| 227 width() - 2 * kBackgroundHoriMargin, | |
| 228 bh - kBackgroundVertMargin * 2); | |
| 229 } | |
| 230 } | 219 } |
| 231 | 220 |
| 232 bool LocationBarView::CanProcessTabKeyEvents() { | 221 bool LocationBarView::CanProcessTabKeyEvents() { |
| 233 // We want to receive tab key events when the hint is showing. | 222 // We want to receive tab key events when the hint is showing. |
| 234 return keyword_hint_view_.IsVisible(); | 223 return keyword_hint_view_.IsVisible(); |
| 235 } | 224 } |
| 236 | 225 |
| 237 void LocationBarView::VisibleBoundsInRootChanged() { | 226 void LocationBarView::VisibleBoundsInRootChanged() { |
| 238 location_entry_->ClosePopup(); | 227 location_entry_->ClosePopup(); |
| 239 } | 228 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 322 |
| 334 void LocationBarView::DoLayout(const bool force_layout) { | 323 void LocationBarView::DoLayout(const bool force_layout) { |
| 335 if (!location_entry_.get()) | 324 if (!location_entry_.get()) |
| 336 return; | 325 return; |
| 337 | 326 |
| 338 RECT formatting_rect; | 327 RECT formatting_rect; |
| 339 location_entry_->GetRect(&formatting_rect); | 328 location_entry_->GetRect(&formatting_rect); |
| 340 RECT edit_bounds; | 329 RECT edit_bounds; |
| 341 location_entry_->GetClientRect(&edit_bounds); | 330 location_entry_->GetClientRect(&edit_bounds); |
| 342 | 331 |
| 343 int entry_width = width() - kEntryPadding - kEntryPadding; | 332 int entry_width = width() - (kEntryPadding * 2); |
| 344 gfx::Size security_image_size; | 333 gfx::Size security_image_size; |
| 345 if (security_image_view_.IsVisible()) { | 334 if (security_image_view_.IsVisible()) { |
| 346 security_image_size = security_image_view_.GetPreferredSize(); | 335 security_image_size = security_image_view_.GetPreferredSize(); |
| 347 entry_width -= security_image_size.width(); | 336 entry_width -= security_image_size.width(); |
| 348 } | 337 } |
| 349 gfx::Size info_label_size; | 338 gfx::Size info_label_size; |
| 350 if (info_label_.IsVisible()) { | 339 if (info_label_.IsVisible()) { |
| 351 info_label_size = info_label_.GetPreferredSize(); | 340 info_label_size = info_label_.GetPreferredSize(); |
| 352 entry_width -= (info_label_size.width() + kInnerPadding); | 341 entry_width -= (info_label_size.width() + kInnerPadding); |
| 353 } | 342 } |
| 354 | 343 |
| 355 const int max_edit_width = entry_width - formatting_rect.left - | 344 const int max_edit_width = entry_width - formatting_rect.left - |
| 356 (edit_bounds.right - formatting_rect.right); | 345 (edit_bounds.right - formatting_rect.right); |
| 357 if (max_edit_width < 0) | 346 if (max_edit_width < 0) |
| 358 return; | 347 return; |
| 359 const int text_width = TextDisplayWidth(); | 348 const int text_width = TextDisplayWidth(); |
| 360 bool needs_layout = force_layout; | 349 bool needs_layout = force_layout; |
| 361 needs_layout |= AdjustHints(text_width, max_edit_width); | 350 needs_layout |= AdjustHints(text_width, max_edit_width); |
| 362 | 351 |
| 363 if (!needs_layout) | 352 if (!needs_layout) |
| 364 return; | 353 return; |
| 365 | 354 |
| 366 // TODO(sky): baseline layout. | 355 // TODO(sky): baseline layout. |
| 367 const SkBitmap* background = | 356 int location_y = TopMargin(); |
| 368 popup_window_mode_ ? kPopupBackground : kBackground; | 357 int location_height = height() - location_y - kVertMargin; |
| 369 int bh = background->height(); | |
| 370 int location_y = ((height() - bh) / 2) + kTextVertMargin; | |
| 371 int location_height = bh - (2 * kTextVertMargin); | |
| 372 if (info_label_.IsVisible()) { | 358 if (info_label_.IsVisible()) { |
| 373 info_label_.SetBounds(width() - kEntryPadding - info_label_size.width(), | 359 info_label_.SetBounds(width() - kEntryPadding - info_label_size.width(), |
| 374 location_y, | 360 location_y, |
| 375 info_label_size.width(), location_height); | 361 info_label_size.width(), location_height); |
| 376 } | 362 } |
| 377 if (security_image_view_.IsVisible()) { | 363 if (security_image_view_.IsVisible()) { |
| 378 const int info_label_width = info_label_size.width() ? | 364 const int info_label_width = info_label_size.width() ? |
| 379 info_label_size.width() + kInnerPadding : 0; | 365 info_label_size.width() + kInnerPadding : 0; |
| 380 security_image_view_.SetBounds(width() - kEntryPadding - | 366 security_image_view_.SetBounds(width() - kEntryPadding - info_label_width - |
| 381 info_label_width - | 367 security_image_size.width(), location_y, security_image_size.width(), |
| 382 security_image_size.width(), | 368 location_height); |
| 383 location_y, | |
| 384 security_image_size.width(), location_height)
; | |
| 385 } | 369 } |
| 386 gfx::Rect location_bounds(kEntryPadding, location_y, entry_width, | 370 gfx::Rect location_bounds(kEntryPadding, location_y, entry_width, |
| 387 location_height); | 371 location_height); |
| 388 if (selected_keyword_view_.IsVisible()) { | 372 if (selected_keyword_view_.IsVisible()) { |
| 389 LayoutView(true, &selected_keyword_view_, text_width, max_edit_width, | 373 LayoutView(true, &selected_keyword_view_, text_width, max_edit_width, |
| 390 &location_bounds); | 374 &location_bounds); |
| 391 } else if (keyword_hint_view_.IsVisible()) { | 375 } else if (keyword_hint_view_.IsVisible()) { |
| 392 LayoutView(false, &keyword_hint_view_, text_width, max_edit_width, | 376 LayoutView(false, &keyword_hint_view_, text_width, max_edit_width, |
| 393 &location_bounds); | 377 &location_bounds); |
| 394 } else if (type_to_search_view_.IsVisible()) { | 378 } else if (type_to_search_view_.IsVisible()) { |
| 395 LayoutView(false, &type_to_search_view_, text_width, max_edit_width, | 379 LayoutView(false, &type_to_search_view_, text_width, max_edit_width, |
| 396 &location_bounds); | 380 &location_bounds); |
| 397 } | 381 } |
| 398 | 382 |
| 399 location_entry_view_->SetBounds(location_bounds.x(), | 383 location_entry_view_->SetBounds(location_bounds.x(), |
| 400 location_bounds.y(), | 384 location_bounds.y(), |
| 401 location_bounds.width(), | 385 location_bounds.width(), |
| 402 location_bounds.height()); | 386 location_bounds.height()); |
| 403 if (!force_layout) { | 387 if (!force_layout) { |
| 404 // If force_layout is false and we got this far it means one of the views | 388 // If force_layout is false and we got this far it means one of the views |
| 405 // was added/removed or changed in size. We need to paint ourselves. | 389 // was added/removed or changed in size. We need to paint ourselves. |
| 406 SchedulePaint(); | 390 SchedulePaint(); |
| 407 } | 391 } |
| 408 } | 392 } |
| 409 | 393 |
| 394 int LocationBarView::TopOffset() const { |
| 395 return (popup_window_mode_ && win_util::ShouldUseVistaFrame()) ? 1 : 0; |
| 396 } |
| 397 |
| 398 int LocationBarView::TopMargin() const { |
| 399 return kVertMargin - TopOffset(); |
| 400 } |
| 401 |
| 410 int LocationBarView::TextDisplayWidth() { | 402 int LocationBarView::TextDisplayWidth() { |
| 411 POINT last_char_position = | 403 POINT last_char_position = |
| 412 location_entry_->PosFromChar(location_entry_->GetTextLength()); | 404 location_entry_->PosFromChar(location_entry_->GetTextLength()); |
| 413 POINT scroll_position; | 405 POINT scroll_position; |
| 414 location_entry_->GetScrollPos(&scroll_position); | 406 location_entry_->GetScrollPos(&scroll_position); |
| 415 const int position_x = last_char_position.x + scroll_position.x; | 407 const int position_x = last_char_position.x + scroll_position.x; |
| 416 return UILayoutIsRightToLeft() ? width() - position_x : position_x; | 408 return UILayoutIsRightToLeft() ? width() - position_x : position_x; |
| 417 } | 409 } |
| 418 | 410 |
| 419 bool LocationBarView::UsePref(int pref_width, int text_width, int max_width) { | 411 bool LocationBarView::UsePref(int pref_width, int text_width, int max_width) { |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 } | 994 } |
| 1003 | 995 |
| 1004 void LocationBarView::FocusSearch() { | 996 void LocationBarView::FocusSearch() { |
| 1005 location_entry_->SetUserText(L"?"); | 997 location_entry_->SetUserText(L"?"); |
| 1006 location_entry_->SetFocus(); | 998 location_entry_->SetFocus(); |
| 1007 } | 999 } |
| 1008 | 1000 |
| 1009 void LocationBarView::SaveStateToContents(TabContents* contents) { | 1001 void LocationBarView::SaveStateToContents(TabContents* contents) { |
| 1010 location_entry_->SaveStateToTab(contents); | 1002 location_entry_->SaveStateToTab(contents); |
| 1011 } | 1003 } |
| OLD | NEW |