| OLD | NEW |
| 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/browser_commands.h" | 5 #include "chrome/browser/ui/browser_commands.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_editor.h" | 10 #include "chrome/browser/bookmarks/bookmark_editor.h" |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 find_tab_helper()->StartFinding(find_text, | 696 find_tab_helper()->StartFinding(find_text, |
| 697 forward_direction, | 697 forward_direction, |
| 698 false); // Not case sensitive. | 698 false); // Not case sensitive. |
| 699 } | 699 } |
| 700 } | 700 } |
| 701 | 701 |
| 702 void Zoom(Browser* browser, content::PageZoom zoom) { | 702 void Zoom(Browser* browser, content::PageZoom zoom) { |
| 703 if (browser->is_devtools()) | 703 if (browser->is_devtools()) |
| 704 return; | 704 return; |
| 705 | 705 |
| 706 content::RenderViewHost* host = | 706 chrome_page_zoom::Zoom(GetActiveWebContents(browser), zoom); |
| 707 GetActiveWebContents(browser)->GetRenderViewHost(); | |
| 708 if (zoom == content::PAGE_ZOOM_RESET) { | |
| 709 host->SetZoomLevel(0); | |
| 710 content::RecordAction(UserMetricsAction("ZoomNormal")); | |
| 711 return; | |
| 712 } | |
| 713 | |
| 714 double current_zoom_level = GetActiveWebContents(browser)->GetZoomLevel(); | |
| 715 double default_zoom_level = | |
| 716 browser->profile()->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); | |
| 717 | |
| 718 // Generate a vector of zoom levels from an array of known presets along with | |
| 719 // the default level added if necessary. | |
| 720 std::vector<double> zoom_levels = | |
| 721 chrome_page_zoom::PresetZoomLevels(default_zoom_level); | |
| 722 | |
| 723 if (zoom == content::PAGE_ZOOM_OUT) { | |
| 724 // Iterate through the zoom levels in reverse order to find the next | |
| 725 // lower level based on the current zoom level for this page. | |
| 726 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); | |
| 727 i != zoom_levels.rend(); ++i) { | |
| 728 double zoom_level = *i; | |
| 729 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) | |
| 730 continue; | |
| 731 if (zoom_level < current_zoom_level) { | |
| 732 host->SetZoomLevel(zoom_level); | |
| 733 content::RecordAction(UserMetricsAction("ZoomMinus")); | |
| 734 return; | |
| 735 } | |
| 736 content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum")); | |
| 737 } | |
| 738 } else { | |
| 739 // Iterate through the zoom levels in normal order to find the next | |
| 740 // higher level based on the current zoom level for this page. | |
| 741 for (std::vector<double>::const_iterator i = zoom_levels.begin(); | |
| 742 i != zoom_levels.end(); ++i) { | |
| 743 double zoom_level = *i; | |
| 744 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) | |
| 745 continue; | |
| 746 if (zoom_level > current_zoom_level) { | |
| 747 host->SetZoomLevel(zoom_level); | |
| 748 content::RecordAction(UserMetricsAction("ZoomPlus")); | |
| 749 return; | |
| 750 } | |
| 751 } | |
| 752 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); | |
| 753 } | |
| 754 } | 707 } |
| 755 | 708 |
| 756 void FocusToolbar(Browser* browser) { | 709 void FocusToolbar(Browser* browser) { |
| 757 content::RecordAction(UserMetricsAction("FocusToolbar")); | 710 content::RecordAction(UserMetricsAction("FocusToolbar")); |
| 758 browser->window()->FocusToolbar(); | 711 browser->window()->FocusToolbar(); |
| 759 } | 712 } |
| 760 | 713 |
| 761 void FocusLocationBar(Browser* browser) { | 714 void FocusLocationBar(Browser* browser) { |
| 762 content::RecordAction(UserMetricsAction("FocusLocation")); | 715 content::RecordAction(UserMetricsAction("FocusLocation")); |
| 763 browser->window()->SetFocusToLocationBar(true); | 716 browser->window()->SetFocusToLocationBar(true); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 if (!tab_contents) | 908 if (!tab_contents) |
| 956 tab_contents = new TabContents(contents); | 909 tab_contents = new TabContents(contents); |
| 957 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true); | 910 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true); |
| 958 | 911 |
| 959 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 912 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 960 contents->GetRenderViewHost()->SyncRendererPrefs(); | 913 contents->GetRenderViewHost()->SyncRendererPrefs(); |
| 961 app_browser->window()->Show(); | 914 app_browser->window()->Show(); |
| 962 } | 915 } |
| 963 | 916 |
| 964 } // namespace chrome | 917 } // namespace chrome |
| OLD | NEW |