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

Side by Side Diff: views/controls/menu/menu_item_view.cc

Issue 388007: Fixes possible crash in showing bookmark menu. The problem occurred... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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
« no previous file with comments | « views/controls/menu/menu_item_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "views/controls/menu/menu_item_view.h" 5 #include "views/controls/menu/menu_item_view.h"
6 6
7 #include "app/gfx/canvas.h" 7 #include "app/gfx/canvas.h"
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 #include "grit/app_strings.h" 9 #include "grit/app_strings.h"
10 #include "views/controls/menu/menu_config.h" 10 #include "views/controls/menu/menu_config.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 submenu_ = new SubmenuView(this); 158 submenu_ = new SubmenuView(this);
159 return submenu_; 159 return submenu_;
160 } 160 }
161 161
162 void MenuItemView::SetSelected(bool selected) { 162 void MenuItemView::SetSelected(bool selected) {
163 selected_ = selected; 163 selected_ = selected;
164 SchedulePaint(); 164 SchedulePaint();
165 } 165 }
166 166
167 void MenuItemView::SetIcon(const SkBitmap& icon, int item_id) { 167 void MenuItemView::SetIcon(const SkBitmap& icon, int item_id) {
168 MenuItemView* item = GetDescendantByID(item_id); 168 MenuItemView* item = GetMenuItemByID(item_id);
169 DCHECK(item); 169 DCHECK(item);
170 item->SetIcon(icon); 170 item->SetIcon(icon);
171 } 171 }
172 172
173 void MenuItemView::SetIcon(const SkBitmap& icon) { 173 void MenuItemView::SetIcon(const SkBitmap& icon) {
174 icon_ = icon; 174 icon_ = icon;
175 SchedulePaint(); 175 SchedulePaint();
176 } 176 }
177 177
178 void MenuItemView::Paint(gfx::Canvas* canvas) { 178 void MenuItemView::Paint(gfx::Canvas* canvas) {
(...skipping 30 matching lines...) Expand all
209 index = title.find('&', index); 209 index = title.find('&', index);
210 if (index != std::wstring::npos) { 210 if (index != std::wstring::npos) {
211 if (index + 1 != title.size() && title[index + 1] != '&') 211 if (index + 1 != title.size() && title[index + 1] != '&')
212 return title[index + 1]; 212 return title[index + 1];
213 index++; 213 index++;
214 } 214 }
215 } while (index != std::wstring::npos); 215 } while (index != std::wstring::npos);
216 return 0; 216 return 0;
217 } 217 }
218 218
219 MenuItemView* MenuItemView::GetMenuItemByID(int id) {
220 if (GetCommand() == id)
221 return this;
222 if (!HasSubmenu())
223 return NULL;
224 for (int i = 0; i < GetSubmenu()->GetChildViewCount(); ++i) {
225 View* child = GetSubmenu()->GetChildViewAt(i);
226 if (child->GetID() == MenuItemView::kMenuItemViewID) {
227 MenuItemView* result = static_cast<MenuItemView*>(child)->
228 GetMenuItemByID(id);
229 if (result)
230 return result;
231 }
232 }
233 return NULL;
234 }
235
219 MenuItemView::MenuItemView(MenuItemView* parent, 236 MenuItemView::MenuItemView(MenuItemView* parent,
220 int command, 237 int command,
221 MenuItemView::Type type) { 238 MenuItemView::Type type) {
222 Init(parent, command, type, NULL); 239 Init(parent, command, type, NULL);
223 } 240 }
224 241
225 // Calculates all sizes that we can from the OS. 242 // Calculates all sizes that we can from the OS.
226 // 243 //
227 // This is invoked prior to Running a menu. 244 // This is invoked prior to Running a menu.
228 void MenuItemView::UpdateMenuPartSizes(bool has_icons) { 245 void MenuItemView::UpdateMenuPartSizes(bool has_icons) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 item->SetTitle(GetDelegate()->GetLabel(item_id)); 301 item->SetTitle(GetDelegate()->GetLabel(item_id));
285 else 302 else
286 item->SetTitle(label); 303 item->SetTitle(label);
287 item->SetIcon(icon); 304 item->SetIcon(icon);
288 if (type == SUBMENU) 305 if (type == SUBMENU)
289 item->CreateSubmenu(); 306 item->CreateSubmenu();
290 submenu_->AddChildView(item); 307 submenu_->AddChildView(item);
291 return item; 308 return item;
292 } 309 }
293 310
294 MenuItemView* MenuItemView::GetDescendantByID(int id) {
295 if (GetCommand() == id)
296 return this;
297 if (!HasSubmenu())
298 return NULL;
299 for (int i = 0; i < GetSubmenu()->GetChildViewCount(); ++i) {
300 View* child = GetSubmenu()->GetChildViewAt(i);
301 if (child->GetID() == MenuItemView::kMenuItemViewID) {
302 MenuItemView* result = static_cast<MenuItemView*>(child)->
303 GetDescendantByID(id);
304 if (result)
305 return result;
306 }
307 }
308 return NULL;
309 }
310
311 void MenuItemView::DropMenuClosed(bool notify_delegate) { 311 void MenuItemView::DropMenuClosed(bool notify_delegate) {
312 DCHECK(controller_); 312 DCHECK(controller_);
313 DCHECK(!controller_->IsBlockingRun()); 313 DCHECK(!controller_->IsBlockingRun());
314 if (MenuController::GetActiveInstance() == controller_) 314 if (MenuController::GetActiveInstance() == controller_)
315 MenuController::SetActiveInstance(NULL); 315 MenuController::SetActiveInstance(NULL);
316 delete controller_; 316 delete controller_;
317 controller_ = NULL; 317 controller_ = NULL;
318 318
319 RemoveEmptyMenus(); 319 RemoveEmptyMenus();
320 320
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } 415 }
416 416
417 int MenuItemView::GetBottomMargin() { 417 int MenuItemView::GetBottomMargin() {
418 MenuItemView* root = GetRootMenuItem(); 418 MenuItemView* root = GetRootMenuItem();
419 return root && root->has_icons_ 419 return root && root->has_icons_
420 ? MenuConfig::instance().item_bottom_margin : 420 ? MenuConfig::instance().item_bottom_margin :
421 MenuConfig::instance().item_no_icon_bottom_margin; 421 MenuConfig::instance().item_no_icon_bottom_margin;
422 } 422 }
423 423
424 } // namespace views 424 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/menu/menu_item_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698