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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller.mm

Issue 181723006: Handle mac trackpad zoom via GesturePinch events (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: jdduke CR feedback and fix win build errors Created 6 years, 9 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <numeric> 8 #include <numeric>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 1850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1861 // Ensure the command is valid first (ExecuteCommand() won't do that) and 1861 // Ensure the command is valid first (ExecuteCommand() won't do that) and
1862 // then make it so. 1862 // then make it so.
1863 if (chrome::IsCommandEnabled(browser_.get(), command)) { 1863 if (chrome::IsCommandEnabled(browser_.get(), command)) {
1864 chrome::ExecuteCommandWithDisposition( 1864 chrome::ExecuteCommandWithDisposition(
1865 browser_.get(), 1865 browser_.get(),
1866 command, 1866 command,
1867 ui::WindowOpenDispositionFromNSEvent(event)); 1867 ui::WindowOpenDispositionFromNSEvent(event));
1868 } 1868 }
1869 } 1869 }
1870 1870
1871 // Called repeatedly during a pinch gesture, with incremental change values.
1872 - (void)magnifyWithEvent:(NSEvent*)event {
1873 // The deltaZ difference necessary to trigger a zoom action. Derived from
1874 // experimentation to find a value that feels reasonable.
1875 const float kZoomStepValue = 0.6;
1876
1877 // Find the (absolute) thresholds on either side of the current zoom factor,
1878 // then convert those to actual numbers to trigger a zoom in or out.
1879 // This logic deliberately makes the range around the starting zoom value for
1880 // the gesture twice as large as the other ranges (i.e., the notches are at
1881 // ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1882 // so that it's easier to get back to your starting point than it is to
1883 // overshoot.
1884 float nextStep = (abs(currentZoomStepDelta_) + 1) * kZoomStepValue;
1885 float backStep = abs(currentZoomStepDelta_) * kZoomStepValue;
1886 float zoomInThreshold = (currentZoomStepDelta_ >= 0) ? nextStep : -backStep;
1887 float zoomOutThreshold = (currentZoomStepDelta_ <= 0) ? -nextStep : backStep;
1888
1889 unsigned int command = 0;
1890 totalMagnifyGestureAmount_ += [event magnification];
1891 if (totalMagnifyGestureAmount_ > zoomInThreshold) {
1892 command = IDC_ZOOM_PLUS;
1893 } else if (totalMagnifyGestureAmount_ < zoomOutThreshold) {
1894 command = IDC_ZOOM_MINUS;
1895 }
1896
1897 if (command && chrome::IsCommandEnabled(browser_.get(), command)) {
1898 currentZoomStepDelta_ += (command == IDC_ZOOM_PLUS) ? 1 : -1;
1899 chrome::ExecuteCommandWithDisposition(
1900 browser_.get(),
1901 command,
1902 ui::WindowOpenDispositionFromNSEvent(event));
1903 }
1904 }
1905
1906 // Delegate method called when window is resized. 1871 // Delegate method called when window is resized.
1907 - (void)windowDidResize:(NSNotification*)notification { 1872 - (void)windowDidResize:(NSNotification*)notification {
1908 [self saveWindowPositionIfNeeded]; 1873 [self saveWindowPositionIfNeeded];
1909 1874
1910 // Resize (and possibly move) the status bubble. Note that we may get called 1875 // Resize (and possibly move) the status bubble. Note that we may get called
1911 // when the status bubble does not exist. 1876 // when the status bubble does not exist.
1912 if (statusBubble_) { 1877 if (statusBubble_) {
1913 statusBubble_->UpdateSizeAndPosition(); 1878 statusBubble_->UpdateSizeAndPosition();
1914 } 1879 }
1915 1880
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
2324 2289
2325 - (BOOL)supportsBookmarkBar { 2290 - (BOOL)supportsBookmarkBar {
2326 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; 2291 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR];
2327 } 2292 }
2328 2293
2329 - (BOOL)isTabbedWindow { 2294 - (BOOL)isTabbedWindow {
2330 return browser_->is_type_tabbed(); 2295 return browser_->is_type_tabbed();
2331 } 2296 }
2332 2297
2333 @end // @implementation BrowserWindowController(WindowType) 2298 @end // @implementation BrowserWindowController(WindowType)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698