| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" | 7 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 25 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
| 26 #include "grit/theme_resources_standard.h" | 26 #include "grit/theme_resources_standard.h" |
| 27 #include "net/base/registry_controlled_domain.h" | 27 #include "net/base/registry_controlled_domain.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 30 #include "ui/base/text/text_elider.h" | 30 #include "ui/base/text/text_elider.h" |
| 31 #include "ui/gfx/codec/png_codec.h" | 31 #include "ui/gfx/codec/png_codec.h" |
| 32 | 32 |
| 33 using content::NavigationController; |
| 33 using content::NavigationEntry; | 34 using content::NavigationEntry; |
| 34 using content::UserMetricsAction; | 35 using content::UserMetricsAction; |
| 35 using content::WebContents; | 36 using content::WebContents; |
| 36 | 37 |
| 37 const int BackForwardMenuModel::kMaxHistoryItems = 12; | 38 const int BackForwardMenuModel::kMaxHistoryItems = 12; |
| 38 const int BackForwardMenuModel::kMaxChapterStops = 5; | 39 const int BackForwardMenuModel::kMaxChapterStops = 5; |
| 39 static const int kMaxWidth = 700; | 40 static const int kMaxWidth = 700; |
| 40 | 41 |
| 41 BackForwardMenuModel::BackForwardMenuModel(Browser* browser, | 42 BackForwardMenuModel::BackForwardMenuModel(Browser* browser, |
| 42 ModelType model_type) | 43 ModelType model_type) |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 ++chapter_stops; | 329 ++chapter_stops; |
| 329 } while (chapter_id != -1 && chapter_stops < kMaxChapterStops); | 330 } while (chapter_id != -1 && chapter_stops < kMaxChapterStops); |
| 330 } | 331 } |
| 331 | 332 |
| 332 return chapter_stops; | 333 return chapter_stops; |
| 333 } | 334 } |
| 334 | 335 |
| 335 int BackForwardMenuModel::GetIndexOfNextChapterStop(int start_from, | 336 int BackForwardMenuModel::GetIndexOfNextChapterStop(int start_from, |
| 336 bool forward) const { | 337 bool forward) const { |
| 337 WebContents* contents = GetWebContents(); | 338 WebContents* contents = GetWebContents(); |
| 338 content::NavigationController& controller = contents->GetController(); | 339 NavigationController& controller = contents->GetController(); |
| 339 | 340 |
| 340 int max_count = controller.GetEntryCount(); | 341 int max_count = controller.GetEntryCount(); |
| 341 if (start_from < 0 || start_from >= max_count) | 342 if (start_from < 0 || start_from >= max_count) |
| 342 return -1; // Out of bounds. | 343 return -1; // Out of bounds. |
| 343 | 344 |
| 344 if (forward) { | 345 if (forward) { |
| 345 if (start_from < max_count - 1) { | 346 if (start_from < max_count - 1) { |
| 346 // We want to advance over the current chapter stop, so we add one. | 347 // We want to advance over the current chapter stop, so we add one. |
| 347 // We don't need to do this when direction is backwards. | 348 // We don't need to do this when direction is backwards. |
| 348 start_from++; | 349 start_from++; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 // This menu item is a chapter stop located between the two separators. | 439 // This menu item is a chapter stop located between the two separators. |
| 439 index = FindChapterStop(history_items, | 440 index = FindChapterStop(history_items, |
| 440 model_type_ == FORWARD_MENU, | 441 model_type_ == FORWARD_MENU, |
| 441 index - history_items - 1); | 442 index - history_items - 1); |
| 442 | 443 |
| 443 return index; | 444 return index; |
| 444 } | 445 } |
| 445 | 446 |
| 446 NavigationEntry* BackForwardMenuModel::GetNavigationEntry(int index) const { | 447 NavigationEntry* BackForwardMenuModel::GetNavigationEntry(int index) const { |
| 447 int controller_index = MenuIndexToNavEntryIndex(index); | 448 int controller_index = MenuIndexToNavEntryIndex(index); |
| 448 content::NavigationController& controller = GetWebContents()->GetController(); | 449 NavigationController& controller = GetWebContents()->GetController(); |
| 449 if (controller_index >= 0 && controller_index < controller.GetEntryCount()) | 450 if (controller_index >= 0 && controller_index < controller.GetEntryCount()) |
| 450 return controller.GetEntryAtIndex(controller_index); | 451 return controller.GetEntryAtIndex(controller_index); |
| 451 | 452 |
| 452 NOTREACHED(); | 453 NOTREACHED(); |
| 453 return NULL; | 454 return NULL; |
| 454 } | 455 } |
| 455 | 456 |
| 456 std::string BackForwardMenuModel::BuildActionName( | 457 std::string BackForwardMenuModel::BuildActionName( |
| 457 const std::string& action, int index) const { | 458 const std::string& action, int index) const { |
| 458 DCHECK(!action.empty()); | 459 DCHECK(!action.empty()); |
| 459 DCHECK(index >= -1); | 460 DCHECK(index >= -1); |
| 460 std::string metric_string; | 461 std::string metric_string; |
| 461 if (model_type_ == FORWARD_MENU) | 462 if (model_type_ == FORWARD_MENU) |
| 462 metric_string += "ForwardMenu_"; | 463 metric_string += "ForwardMenu_"; |
| 463 else | 464 else |
| 464 metric_string += "BackMenu_"; | 465 metric_string += "BackMenu_"; |
| 465 metric_string += action; | 466 metric_string += action; |
| 466 if (index != -1) { | 467 if (index != -1) { |
| 467 // +1 is for historical reasons (indices used to start at 1). | 468 // +1 is for historical reasons (indices used to start at 1). |
| 468 metric_string += base::IntToString(index + 1); | 469 metric_string += base::IntToString(index + 1); |
| 469 } | 470 } |
| 470 return metric_string; | 471 return metric_string; |
| 471 } | 472 } |
| OLD | NEW |