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 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 find_tab_helper()->StartFinding(find_text, | 756 find_tab_helper()->StartFinding(find_text, |
757 forward_direction, | 757 forward_direction, |
758 false); // Not case sensitive. | 758 false); // Not case sensitive. |
759 } | 759 } |
760 } | 760 } |
761 | 761 |
762 void Zoom(Browser* browser, content::PageZoom zoom) { | 762 void Zoom(Browser* browser, content::PageZoom zoom) { |
763 if (browser->is_devtools()) | 763 if (browser->is_devtools()) |
764 return; | 764 return; |
765 | 765 |
766 content::RenderViewHost* host = | 766 chrome_page_zoom::Zoom(GetActiveWebContents(browser), zoom); |
767 GetActiveWebContents(browser)->GetRenderViewHost(); | |
768 if (zoom == content::PAGE_ZOOM_RESET) { | |
769 host->SetZoomLevel(0); | |
770 content::RecordAction(UserMetricsAction("ZoomNormal")); | |
771 return; | |
772 } | |
773 | |
774 double current_zoom_level = GetActiveWebContents(browser)->GetZoomLevel(); | |
775 double default_zoom_level = | |
776 browser->profile()->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); | |
777 | |
778 // Generate a vector of zoom levels from an array of known presets along with | |
779 // the default level added if necessary. | |
780 std::vector<double> zoom_levels = | |
781 chrome_page_zoom::PresetZoomLevels(default_zoom_level); | |
782 | |
783 if (zoom == content::PAGE_ZOOM_OUT) { | |
784 // Iterate through the zoom levels in reverse order to find the next | |
785 // lower level based on the current zoom level for this page. | |
786 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); | |
787 i != zoom_levels.rend(); ++i) { | |
788 double zoom_level = *i; | |
789 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) | |
790 continue; | |
791 if (zoom_level < current_zoom_level) { | |
792 host->SetZoomLevel(zoom_level); | |
793 content::RecordAction(UserMetricsAction("ZoomMinus")); | |
794 return; | |
795 } | |
796 content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum")); | |
797 } | |
798 } else { | |
799 // Iterate through the zoom levels in normal order to find the next | |
800 // higher level based on the current zoom level for this page. | |
801 for (std::vector<double>::const_iterator i = zoom_levels.begin(); | |
802 i != zoom_levels.end(); ++i) { | |
803 double zoom_level = *i; | |
804 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) | |
805 continue; | |
806 if (zoom_level > current_zoom_level) { | |
807 host->SetZoomLevel(zoom_level); | |
808 content::RecordAction(UserMetricsAction("ZoomPlus")); | |
809 return; | |
810 } | |
811 } | |
812 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); | |
813 } | |
814 } | 767 } |
815 | 768 |
816 void FocusToolbar(Browser* browser) { | 769 void FocusToolbar(Browser* browser) { |
817 content::RecordAction(UserMetricsAction("FocusToolbar")); | 770 content::RecordAction(UserMetricsAction("FocusToolbar")); |
818 browser->window()->FocusToolbar(); | 771 browser->window()->FocusToolbar(); |
819 } | 772 } |
820 | 773 |
821 void FocusLocationBar(Browser* browser) { | 774 void FocusLocationBar(Browser* browser) { |
822 content::RecordAction(UserMetricsAction("FocusLocation")); | 775 content::RecordAction(UserMetricsAction("FocusLocation")); |
823 browser->window()->SetFocusToLocationBar(true); | 776 browser->window()->SetFocusToLocationBar(true); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 if (!tab_contents) | 983 if (!tab_contents) |
1031 tab_contents = new TabContents(contents); | 984 tab_contents = new TabContents(contents); |
1032 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true); | 985 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true); |
1033 | 986 |
1034 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 987 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
1035 contents->GetRenderViewHost()->SyncRendererPrefs(); | 988 contents->GetRenderViewHost()->SyncRendererPrefs(); |
1036 app_browser->window()->Show(); | 989 app_browser->window()->Show(); |
1037 } | 990 } |
1038 | 991 |
1039 } // namespace chrome | 992 } // namespace chrome |
OLD | NEW |