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

Side by Side Diff: ui/app_list/cocoa/apps_search_results_model_bridge.mm

Issue 2131463002: Purge the App Launcher code from Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Zap mac-specific icon assets Created 4 years, 5 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
OLDNEW
(Empty)
1 // Copyright 2013 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 #import "ui/app_list/cocoa/apps_search_results_model_bridge.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "base/macros.h"
10 #include "base/strings/sys_string_conversions.h"
11 #include "ui/app_list/app_list_model.h"
12 #import "ui/app_list/cocoa/apps_search_results_controller.h"
13 #include "ui/app_list/search_result.h"
14 #include "ui/app_list/search_result_observer.h"
15 #import "ui/base/cocoa/menu_controller.h"
16
17 namespace app_list {
18
19 class AppsSearchResultsModelBridge::ItemObserver : public SearchResultObserver {
20 public:
21 ItemObserver(AppsSearchResultsModelBridge* bridge, size_t index)
22 : bridge_(bridge), row_in_view_(index) {
23 // Cache the result, because the results array is updated before notifying
24 // observers (which happens before deleting the SearchResult).
25 result_ = [bridge_->parent_ results]->GetItemAt(index);
26 result_->AddObserver(this);
27 }
28
29 ~ItemObserver() override { result_->RemoveObserver(this); }
30
31 NSMenu* GetContextMenu() {
32 if (!context_menu_controller_) {
33 ui::MenuModel* menu_model = result_->GetContextMenuModel();
34 if (!menu_model)
35 return nil;
36
37 context_menu_controller_.reset(
38 [[MenuController alloc] initWithModel:menu_model
39 useWithPopUpButtonCell:NO]);
40 }
41 return [context_menu_controller_ menu];
42 }
43
44 // SearchResultObserver overrides:
45 void OnIconChanged() override {
46 bridge_->ReloadDataForItems(row_in_view_, 1);
47 }
48 void OnActionsChanged() override {}
49 void OnIsInstallingChanged() override {}
50 void OnPercentDownloadedChanged() override {}
51 void OnItemInstalled() override {}
52
53 private:
54 AppsSearchResultsModelBridge* bridge_; // Weak. Owns us.
55 SearchResult* result_; // Weak. Owned by AppListModel::SearchResults.
56 size_t row_in_view_;
57 base::scoped_nsobject<MenuController> context_menu_controller_;
58
59 DISALLOW_COPY_AND_ASSIGN(ItemObserver);
60 };
61
62 AppsSearchResultsModelBridge::AppsSearchResultsModelBridge(
63 AppsSearchResultsController* results_controller)
64 : parent_(results_controller) {
65 UpdateItemObservers();
66 [parent_ results]->AddObserver(this);
67 }
68
69 AppsSearchResultsModelBridge::~AppsSearchResultsModelBridge() {
70 [parent_ results]->RemoveObserver(this);
71 }
72
73 NSMenu* AppsSearchResultsModelBridge::MenuForItem(size_t index) {
74 DCHECK_LT(index, item_observers_.size());
75 return item_observers_[index]->GetContextMenu();
76 }
77
78 void AppsSearchResultsModelBridge::UpdateItemObservers() {
79 DCHECK(item_observers_.empty());
80 const size_t itemCount = [parent_ results]->item_count();
81 for (size_t i = 0 ; i < itemCount; ++i)
82 item_observers_.push_back(new ItemObserver(this, i));
83 }
84
85 void AppsSearchResultsModelBridge::ReloadDataForItems(
86 size_t start, size_t count) const {
87 NSIndexSet* column = [NSIndexSet indexSetWithIndex:0];
88 NSIndexSet* rows =
89 [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(start, count)];
90 [[parent_ tableView] reloadDataForRowIndexes:rows
91 columnIndexes:column];
92 }
93
94 void AppsSearchResultsModelBridge::ListItemsAdded(
95 size_t start, size_t count) {
96 item_observers_.clear();
97 if (start == static_cast<size_t>([[parent_ tableView] numberOfRows]))
98 [[parent_ tableView] noteNumberOfRowsChanged];
99 else
100 [[parent_ tableView] reloadData];
101 UpdateItemObservers();
102 }
103
104 void AppsSearchResultsModelBridge::ListItemsRemoved(
105 size_t start, size_t count) {
106 item_observers_.clear();
107 if (start == [parent_ results]->item_count())
108 [[parent_ tableView] noteNumberOfRowsChanged];
109 else
110 [[parent_ tableView] reloadData];
111 UpdateItemObservers();
112 }
113
114 void AppsSearchResultsModelBridge::ListItemMoved(
115 size_t index, size_t target_index) {
116 NOTREACHED();
117 }
118
119 void AppsSearchResultsModelBridge::ListItemsChanged(
120 size_t start, size_t count) {
121 item_observers_.clear();
122 ReloadDataForItems(start, count);
123 UpdateItemObservers();
124 }
125
126 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698