Home | History | Annotate | Download | only in cocoa
      1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_UI_COCOA_WINDOW_SIZE_AUTOSAVER_H_
      6 #define CHROME_BROWSER_UI_COCOA_WINDOW_SIZE_AUTOSAVER_H_
      7 #pragma once
      8 
      9 class PrefService;
     10 @class NSWindow;
     11 
     12 // WindowSizeAutosaver is a helper class that makes it easy to let windows
     13 // autoremember their position or position and size in a PrefService object.
     14 // To use this, add a |scoped_nsobject<WindowSizeAutosaver>| to your window
     15 // controller and initialize it in the window controller's init method, passing
     16 // a window and an autosave name. The autosaver will register for "window moved"
     17 // and "window resized" notifications and write the current window state to the
     18 // prefs service every time they fire. The window's size is automatically
     19 // restored when the autosaver's |initWithWindow:...| method is called.
     20 //
     21 // Note: Your xib file should have "Visible at launch" UNCHECKED, so that the
     22 // initial repositioning is not visible.
     23 @interface WindowSizeAutosaver : NSObject {
     24   NSWindow* window_;  // weak
     25   PrefService* prefService_;  // weak
     26   const char* path_;
     27 }
     28 
     29 - (id)initWithWindow:(NSWindow*)window
     30          prefService:(PrefService*)prefs
     31                 path:(const char*)path;
     32 @end
     33 
     34 #endif  // CHROME_BROWSER_UI_COCOA_WINDOW_SIZE_AUTOSAVER_H_
     35 
     36