OLD | NEW |
(Empty) | |
| 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_COCOA_VIEW_ID_UTIL_H_ |
| 6 #define CHROME_BROWSER_COCOA_VIEW_ID_UTIL_H_ |
| 7 |
| 8 #include "gfx/native_widget_types.h" |
| 9 #include "chrome/browser/view_ids.h" |
| 10 |
| 11 namespace view_id_util { |
| 12 |
| 13 // We use NSView's tag property to support ViewID, so we don't need special code |
| 14 // for binding a ViewID to a NSView. The subclasses of NSView shall override tag |
| 15 // method to return their ViewIDs. |
| 16 // However the tag property is also used elsewhere, such as the window buttons |
| 17 // provided by the Cocoa system (the three stoplights on the top left corner), |
| 18 // whose tags will be set to 0, 1, 2 by the Cocoa system. |
| 19 // In order to avoid conflict, we use negative tag value for ViewID. |
| 20 // No existing chromium code uses negative tag value, so it's safe for us to use |
| 21 // it. |
| 22 // See http://dev.chromium.org/developers/design-documents/viewid-support-on-mac |
| 23 // for details. |
| 24 |
| 25 // A convenient function to convert a ViewID value to negative tag value. Using |
| 26 // this function to make sure that we only need to change this fuction when we |
| 27 // have to change the mapping algorithm to avoid conflict in the future. |
| 28 inline int ViewIDToTag(ViewID viewID) { |
| 29 return -viewID - 1; |
| 30 } |
| 31 |
| 32 // A convenient function to lookup a view by a ViewID in a given window. |
| 33 NSView* GetView(NSWindow* window, ViewID viewID); |
| 34 |
| 35 } // namespace view_id_util |
| 36 |
| 37 #endif // CHROME_BROWSER_COCOA_VIEW_ID_UTIL_H_ |
OLD | NEW |