| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 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_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_MAC_H_ | |
| 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_MAC_H_ | |
| 7 | |
| 8 #import <Cocoa/Cocoa.h> | |
| 9 | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/scoped_ptr.h" | |
| 14 #include "base/scoped_nsobject.h" | |
| 15 #include "chrome/browser/autocomplete/autocomplete.h" | |
| 16 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" | |
| 17 #include "webkit/glue/window_open_disposition.h" | |
| 18 | |
| 19 class AutocompletePopupModel; | |
| 20 class AutocompleteEditModel; | |
| 21 class AutocompleteEditViewMac; | |
| 22 @class AutocompleteTableTarget; | |
| 23 class Profile; | |
| 24 | |
| 25 // Implements AutocompletePopupView using a raw NSWindow containing an | |
| 26 // NSTableView. | |
| 27 | |
| 28 class AutocompletePopupViewMac : public AutocompletePopupView { | |
| 29 public: | |
| 30 AutocompletePopupViewMac(AutocompleteEditViewMac* edit_view, | |
| 31 AutocompleteEditModel* edit_model, | |
| 32 Profile* profile); | |
| 33 virtual ~AutocompletePopupViewMac(); | |
| 34 | |
| 35 // Implement the AutocompletePopupView interface. | |
| 36 virtual bool IsOpen() const; | |
| 37 virtual void InvalidateLine(size_t line) { | |
| 38 // TODO(shess): Verify that there is no need to implement this. | |
| 39 // This is currently used in two places in the model: | |
| 40 // | |
| 41 // When setting the selected line, the selected line is | |
| 42 // invalidated, then the selected line is changed, then the new | |
| 43 // selected line is invalidated, then PaintUpdatesNow() is called. | |
| 44 // For us PaintUpdatesNow() should be sufficient. | |
| 45 // | |
| 46 // Same thing happens when changing the hovered line, except with | |
| 47 // no call to PaintUpdatesNow(). Since this code does not | |
| 48 // currently support special display of the hovered line, there's | |
| 49 // nothing to do here. | |
| 50 // | |
| 51 // deanm indicates that this is an anti-flicker optimization, | |
| 52 // which we probably cannot utilize (and may not need) so long as | |
| 53 // we're using NSTableView to implement the popup contents. We | |
| 54 // may need to move away from NSTableView to implement hover, | |
| 55 // though. | |
| 56 } | |
| 57 virtual void UpdatePopupAppearance(); | |
| 58 virtual void OnHoverEnabledOrDisabled(bool disabled) { NOTIMPLEMENTED(); } | |
| 59 | |
| 60 // This is only called by model in SetSelectedLine() after updating | |
| 61 // everything. Popup should already be visible. | |
| 62 virtual void PaintUpdatesNow(); | |
| 63 | |
| 64 // Helpers which forward to model_, otherwise our Objective-C helper | |
| 65 // object would need model_ to be public:. | |
| 66 void StopAutocomplete(); | |
| 67 size_t ResultRowCount(); | |
| 68 const std::wstring& ResultContentsAt(size_t i); | |
| 69 bool ResultStarredAt(size_t i); | |
| 70 const std::wstring& ResultDescriptionAt(size_t i); | |
| 71 void AcceptInput(WindowOpenDisposition disposition, bool for_drop); | |
| 72 | |
| 73 // TODO(shess): Get rid of this. Right now it's needed because of | |
| 74 // the ordering of initialization in tab_contents_controller.mm. | |
| 75 void SetField(NSTextField* field) { | |
| 76 field_ = field; | |
| 77 } | |
| 78 | |
| 79 private: | |
| 80 // Create the popup_ instance if needed. | |
| 81 void CreatePopupIfNeeded(); | |
| 82 | |
| 83 scoped_ptr<AutocompletePopupModel> model_; | |
| 84 AutocompleteEditViewMac* edit_view_; | |
| 85 | |
| 86 NSTextField* field_; // owned by tab controller | |
| 87 | |
| 88 scoped_nsobject<AutocompleteTableTarget> table_target_; | |
| 89 // TODO(shess): Before checkin review implementation to make sure | |
| 90 // that popup_'s object hierarchy doesn't keep references to | |
| 91 // destructed objects. | |
| 92 scoped_nsobject<NSWindow> popup_; | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupViewMac); | |
| 95 }; | |
| 96 | |
| 97 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_MAC_H_ | |
| OLD | NEW |