| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/menu/menu_item_view.h" | 5 #include "ui/views/controls/menu/menu_item_view.h" |
| 6 | 6 |
| 7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 public: | 40 public: |
| 41 explicit EmptyMenuMenuItem(MenuItemView* parent) | 41 explicit EmptyMenuMenuItem(MenuItemView* parent) |
| 42 : MenuItemView(parent, 0, EMPTY) { | 42 : MenuItemView(parent, 0, EMPTY) { |
| 43 // Set this so that we're not identified as a normal menu item. | 43 // Set this so that we're not identified as a normal menu item. |
| 44 set_id(kEmptyMenuItemViewID); | 44 set_id(kEmptyMenuItemViewID); |
| 45 SetTitle(l10n_util::GetStringUTF16(IDS_APP_MENU_EMPTY_SUBMENU)); | 45 SetTitle(l10n_util::GetStringUTF16(IDS_APP_MENU_EMPTY_SUBMENU)); |
| 46 SetEnabled(false); | 46 SetEnabled(false); |
| 47 } | 47 } |
| 48 | 48 |
| 49 virtual bool GetTooltipText(const gfx::Point& p, | 49 virtual bool GetTooltipText(const gfx::Point& p, |
| 50 string16* tooltip) const OVERRIDE { | 50 base::string16* tooltip) const OVERRIDE { |
| 51 // Empty menu items shouldn't have a tooltip. | 51 // Empty menu items shouldn't have a tooltip. |
| 52 return false; | 52 return false; |
| 53 } | 53 } |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 DISALLOW_COPY_AND_ASSIGN(EmptyMenuMenuItem); | 56 DISALLOW_COPY_AND_ASSIGN(EmptyMenuMenuItem); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 | 60 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // NULL delegate. | 109 // NULL delegate. |
| 110 Init(NULL, 0, SUBMENU, delegate); | 110 Init(NULL, 0, SUBMENU, delegate); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void MenuItemView::ChildPreferredSizeChanged(View* child) { | 113 void MenuItemView::ChildPreferredSizeChanged(View* child) { |
| 114 invalidate_dimensions(); | 114 invalidate_dimensions(); |
| 115 PreferredSizeChanged(); | 115 PreferredSizeChanged(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 bool MenuItemView::GetTooltipText(const gfx::Point& p, | 118 bool MenuItemView::GetTooltipText(const gfx::Point& p, |
| 119 string16* tooltip) const { | 119 base::string16* tooltip) const { |
| 120 *tooltip = tooltip_; | 120 *tooltip = tooltip_; |
| 121 if (!tooltip->empty()) | 121 if (!tooltip->empty()) |
| 122 return true; | 122 return true; |
| 123 | 123 |
| 124 if (GetType() == SEPARATOR) | 124 if (GetType() == SEPARATOR) |
| 125 return false; | 125 return false; |
| 126 | 126 |
| 127 const MenuController* controller = GetMenuController(); | 127 const MenuController* controller = GetMenuController(); |
| 128 if (!controller || controller->exit_type() != MenuController::EXIT_NONE) { | 128 if (!controller || controller->exit_type() != MenuController::EXIT_NONE) { |
| 129 // Either the menu has been closed or we're in the process of closing the | 129 // Either the menu has been closed or we're in the process of closing the |
| (...skipping 13 matching lines...) Expand all Loading... |
| 143 CHECK(delegate); | 143 CHECK(delegate); |
| 144 gfx::Point location(p); | 144 gfx::Point location(p); |
| 145 ConvertPointToScreen(this, &location); | 145 ConvertPointToScreen(this, &location); |
| 146 *tooltip = delegate->GetTooltipText(command_, location); | 146 *tooltip = delegate->GetTooltipText(command_, location); |
| 147 return !tooltip->empty(); | 147 return !tooltip->empty(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void MenuItemView::GetAccessibleState(ui::AccessibleViewState* state) { | 150 void MenuItemView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 151 state->role = ui::AccessibilityTypes::ROLE_MENUITEM; | 151 state->role = ui::AccessibilityTypes::ROLE_MENUITEM; |
| 152 | 152 |
| 153 string16 item_text; | 153 base::string16 item_text; |
| 154 if (IsContainer()) { | 154 if (IsContainer()) { |
| 155 // The first child is taking over, just use its accessible name instead of | 155 // The first child is taking over, just use its accessible name instead of |
| 156 // |title_|. | 156 // |title_|. |
| 157 View* child = child_at(0); | 157 View* child = child_at(0); |
| 158 ui::AccessibleViewState state; | 158 ui::AccessibleViewState state; |
| 159 child->GetAccessibleState(&state); | 159 child->GetAccessibleState(&state); |
| 160 item_text = state.name; | 160 item_text = state.name; |
| 161 } else { | 161 } else { |
| 162 item_text = title_; | 162 item_text = title_; |
| 163 } | 163 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 182 | 182 |
| 183 // static | 183 // static |
| 184 bool MenuItemView::IsBubble(MenuItemView::AnchorPosition anchor) { | 184 bool MenuItemView::IsBubble(MenuItemView::AnchorPosition anchor) { |
| 185 return anchor == MenuItemView::BUBBLE_LEFT || | 185 return anchor == MenuItemView::BUBBLE_LEFT || |
| 186 anchor == MenuItemView::BUBBLE_RIGHT || | 186 anchor == MenuItemView::BUBBLE_RIGHT || |
| 187 anchor == MenuItemView::BUBBLE_ABOVE || | 187 anchor == MenuItemView::BUBBLE_ABOVE || |
| 188 anchor == MenuItemView::BUBBLE_BELOW; | 188 anchor == MenuItemView::BUBBLE_BELOW; |
| 189 } | 189 } |
| 190 | 190 |
| 191 // static | 191 // static |
| 192 string16 MenuItemView::GetAccessibleNameForMenuItem( | 192 base::string16 MenuItemView::GetAccessibleNameForMenuItem( |
| 193 const string16& item_text, const string16& minor_text) { | 193 const base::string16& item_text, const base::string16& minor_text) { |
| 194 string16 accessible_name = item_text; | 194 base::string16 accessible_name = item_text; |
| 195 | 195 |
| 196 // Filter out the "&" for accessibility clients. | 196 // Filter out the "&" for accessibility clients. |
| 197 size_t index = 0; | 197 size_t index = 0; |
| 198 const char16 amp = '&'; | 198 const char16 amp = '&'; |
| 199 while ((index = accessible_name.find(amp, index)) != string16::npos && | 199 while ((index = accessible_name.find(amp, index)) != base::string16::npos && |
| 200 index + 1 < accessible_name.length()) { | 200 index + 1 < accessible_name.length()) { |
| 201 accessible_name.replace(index, accessible_name.length() - index, | 201 accessible_name.replace(index, accessible_name.length() - index, |
| 202 accessible_name.substr(index + 1)); | 202 accessible_name.substr(index + 1)); |
| 203 | 203 |
| 204 // Special case for "&&" (escaped for "&"). | 204 // Special case for "&&" (escaped for "&"). |
| 205 if (accessible_name[index] == '&') | 205 if (accessible_name[index] == '&') |
| 206 ++index; | 206 ++index; |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Append subtext. | 209 // Append subtext. |
| 210 if (!minor_text.empty()) { | 210 if (!minor_text.empty()) { |
| 211 accessible_name.push_back(' '); | 211 accessible_name.push_back(' '); |
| 212 accessible_name.append(minor_text); | 212 accessible_name.append(minor_text); |
| 213 } | 213 } |
| 214 | 214 |
| 215 return accessible_name; | 215 return accessible_name; |
| 216 } | 216 } |
| 217 | 217 |
| 218 void MenuItemView::Cancel() { | 218 void MenuItemView::Cancel() { |
| 219 if (controller_ && !canceled_) { | 219 if (controller_ && !canceled_) { |
| 220 canceled_ = true; | 220 canceled_ = true; |
| 221 controller_->Cancel(MenuController::EXIT_ALL); | 221 controller_->Cancel(MenuController::EXIT_ALL); |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 MenuItemView* MenuItemView::AddMenuItemAt( | 225 MenuItemView* MenuItemView::AddMenuItemAt( |
| 226 int index, | 226 int index, |
| 227 int item_id, | 227 int item_id, |
| 228 const string16& label, | 228 const base::string16& label, |
| 229 const string16& sublabel, | 229 const base::string16& sublabel, |
| 230 const string16& minor_text, | 230 const base::string16& minor_text, |
| 231 const gfx::ImageSkia& icon, | 231 const gfx::ImageSkia& icon, |
| 232 Type type, | 232 Type type, |
| 233 ui::MenuSeparatorType separator_style) { | 233 ui::MenuSeparatorType separator_style) { |
| 234 DCHECK_NE(type, EMPTY); | 234 DCHECK_NE(type, EMPTY); |
| 235 DCHECK_LE(0, index); | 235 DCHECK_LE(0, index); |
| 236 if (!submenu_) | 236 if (!submenu_) |
| 237 CreateSubmenu(); | 237 CreateSubmenu(); |
| 238 DCHECK_GE(submenu_->child_count(), index); | 238 DCHECK_GE(submenu_->child_count(), index); |
| 239 if (type == SEPARATOR) { | 239 if (type == SEPARATOR) { |
| 240 submenu_->AddChildViewAt(new MenuSeparator(this, separator_style), index); | 240 submenu_->AddChildViewAt(new MenuSeparator(this, separator_style), index); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 264 DCHECK(item); | 264 DCHECK(item); |
| 265 submenu_->RemoveChildView(item); | 265 submenu_->RemoveChildView(item); |
| 266 | 266 |
| 267 // RemoveChildView() does not delete the item, which is a good thing | 267 // RemoveChildView() does not delete the item, which is a good thing |
| 268 // in case a submenu is being displayed while items are being removed. | 268 // in case a submenu is being displayed while items are being removed. |
| 269 // Deletion will be done by ChildrenChanged() or at destruction. | 269 // Deletion will be done by ChildrenChanged() or at destruction. |
| 270 removed_items_.push_back(item); | 270 removed_items_.push_back(item); |
| 271 } | 271 } |
| 272 | 272 |
| 273 MenuItemView* MenuItemView::AppendMenuItem(int item_id, | 273 MenuItemView* MenuItemView::AppendMenuItem(int item_id, |
| 274 const string16& label, | 274 const base::string16& label, |
| 275 Type type) { | 275 Type type) { |
| 276 return AppendMenuItemImpl(item_id, label, string16(), string16(), | 276 return AppendMenuItemImpl(item_id, label, base::string16(), base::string16(), |
| 277 gfx::ImageSkia(), type, ui::NORMAL_SEPARATOR); | 277 gfx::ImageSkia(), type, ui::NORMAL_SEPARATOR); |
| 278 } | 278 } |
| 279 | 279 |
| 280 MenuItemView* MenuItemView::AppendSubMenu(int item_id, | 280 MenuItemView* MenuItemView::AppendSubMenu(int item_id, |
| 281 const string16& label) { | 281 const base::string16& label) { |
| 282 return AppendMenuItemImpl(item_id, label, string16(), string16(), | 282 return AppendMenuItemImpl(item_id, label, base::string16(), base::string16(), |
| 283 gfx::ImageSkia(), SUBMENU, ui::NORMAL_SEPARATOR); | 283 gfx::ImageSkia(), SUBMENU, ui::NORMAL_SEPARATOR); |
| 284 } | 284 } |
| 285 | 285 |
| 286 MenuItemView* MenuItemView::AppendSubMenuWithIcon(int item_id, | 286 MenuItemView* MenuItemView::AppendSubMenuWithIcon(int item_id, |
| 287 const string16& label, | 287 const base::string16& label, |
| 288 const gfx::ImageSkia& icon) { | 288 const gfx::ImageSkia& icon) { |
| 289 return AppendMenuItemImpl(item_id, label, string16(), string16(), icon, | 289 return AppendMenuItemImpl(item_id, label, base::string16(), base::string16(), |
| 290 SUBMENU, ui::NORMAL_SEPARATOR); | 290 icon, SUBMENU, ui::NORMAL_SEPARATOR); |
| 291 } | 291 } |
| 292 | 292 |
| 293 MenuItemView* MenuItemView::AppendMenuItemWithLabel(int item_id, | 293 MenuItemView* MenuItemView::AppendMenuItemWithLabel( |
| 294 const string16& label) { | 294 int item_id, |
| 295 const base::string16& label) { |
| 295 return AppendMenuItem(item_id, label, NORMAL); | 296 return AppendMenuItem(item_id, label, NORMAL); |
| 296 } | 297 } |
| 297 | 298 |
| 298 MenuItemView* MenuItemView::AppendDelegateMenuItem(int item_id) { | 299 MenuItemView* MenuItemView::AppendDelegateMenuItem(int item_id) { |
| 299 return AppendMenuItem(item_id, string16(), NORMAL); | 300 return AppendMenuItem(item_id, base::string16(), NORMAL); |
| 300 } | 301 } |
| 301 | 302 |
| 302 void MenuItemView::AppendSeparator() { | 303 void MenuItemView::AppendSeparator() { |
| 303 AppendMenuItemImpl(0, string16(), string16(), string16(), gfx::ImageSkia(), | 304 AppendMenuItemImpl(0, base::string16(), base::string16(), base::string16(), |
| 304 SEPARATOR, ui::NORMAL_SEPARATOR); | 305 gfx::ImageSkia(), SEPARATOR, ui::NORMAL_SEPARATOR); |
| 305 } | 306 } |
| 306 | 307 |
| 307 MenuItemView* MenuItemView::AppendMenuItemWithIcon(int item_id, | 308 MenuItemView* MenuItemView::AppendMenuItemWithIcon(int item_id, |
| 308 const string16& label, | 309 const base::string16& label, |
| 309 const gfx::ImageSkia& icon) { | 310 const gfx::ImageSkia& icon) { |
| 310 return AppendMenuItemImpl(item_id, label, string16(), string16(), icon, | 311 return AppendMenuItemImpl(item_id, label, base::string16(), base::string16(), |
| 311 NORMAL, ui::NORMAL_SEPARATOR); | 312 icon, NORMAL, ui::NORMAL_SEPARATOR); |
| 312 } | 313 } |
| 313 | 314 |
| 314 MenuItemView* MenuItemView::AppendMenuItemImpl( | 315 MenuItemView* MenuItemView::AppendMenuItemImpl( |
| 315 int item_id, | 316 int item_id, |
| 316 const string16& label, | 317 const base::string16& label, |
| 317 const string16& sublabel, | 318 const base::string16& sublabel, |
| 318 const string16& minor_text, | 319 const base::string16& minor_text, |
| 319 const gfx::ImageSkia& icon, | 320 const gfx::ImageSkia& icon, |
| 320 Type type, | 321 Type type, |
| 321 ui::MenuSeparatorType separator_style) { | 322 ui::MenuSeparatorType separator_style) { |
| 322 const int index = submenu_ ? submenu_->child_count() : 0; | 323 const int index = submenu_ ? submenu_->child_count() : 0; |
| 323 return AddMenuItemAt(index, item_id, label, sublabel, minor_text, icon, type, | 324 return AddMenuItemAt(index, item_id, label, sublabel, minor_text, icon, type, |
| 324 separator_style); | 325 separator_style); |
| 325 } | 326 } |
| 326 | 327 |
| 327 SubmenuView* MenuItemView::CreateSubmenu() { | 328 SubmenuView* MenuItemView::CreateSubmenu() { |
| 328 if (!submenu_) | 329 if (!submenu_) |
| 329 submenu_ = new SubmenuView(this); | 330 submenu_ = new SubmenuView(this); |
| 330 return submenu_; | 331 return submenu_; |
| 331 } | 332 } |
| 332 | 333 |
| 333 bool MenuItemView::HasSubmenu() const { | 334 bool MenuItemView::HasSubmenu() const { |
| 334 return (submenu_ != NULL); | 335 return (submenu_ != NULL); |
| 335 } | 336 } |
| 336 | 337 |
| 337 SubmenuView* MenuItemView::GetSubmenu() const { | 338 SubmenuView* MenuItemView::GetSubmenu() const { |
| 338 return submenu_; | 339 return submenu_; |
| 339 } | 340 } |
| 340 | 341 |
| 341 void MenuItemView::SetTitle(const string16& title) { | 342 void MenuItemView::SetTitle(const base::string16& title) { |
| 342 title_ = title; | 343 title_ = title; |
| 343 invalidate_dimensions(); // Triggers preferred size recalculation. | 344 invalidate_dimensions(); // Triggers preferred size recalculation. |
| 344 } | 345 } |
| 345 | 346 |
| 346 void MenuItemView::SetSubtitle(const string16& subtitle) { | 347 void MenuItemView::SetSubtitle(const base::string16& subtitle) { |
| 347 subtitle_ = subtitle; | 348 subtitle_ = subtitle; |
| 348 invalidate_dimensions(); // Triggers preferred size recalculation. | 349 invalidate_dimensions(); // Triggers preferred size recalculation. |
| 349 } | 350 } |
| 350 | 351 |
| 351 void MenuItemView::SetMinorText(const string16& minor_text) { | 352 void MenuItemView::SetMinorText(const base::string16& minor_text) { |
| 352 minor_text_ = minor_text; | 353 minor_text_ = minor_text; |
| 353 invalidate_dimensions(); // Triggers preferred size recalculation. | 354 invalidate_dimensions(); // Triggers preferred size recalculation. |
| 354 } | 355 } |
| 355 | 356 |
| 356 void MenuItemView::SetSelected(bool selected) { | 357 void MenuItemView::SetSelected(bool selected) { |
| 357 selected_ = selected; | 358 selected_ = selected; |
| 358 SchedulePaint(); | 359 SchedulePaint(); |
| 359 } | 360 } |
| 360 | 361 |
| 361 void MenuItemView::SetTooltip(const string16& tooltip, int item_id) { | 362 void MenuItemView::SetTooltip(const base::string16& tooltip, int item_id) { |
| 362 MenuItemView* item = GetMenuItemByID(item_id); | 363 MenuItemView* item = GetMenuItemByID(item_id); |
| 363 DCHECK(item); | 364 DCHECK(item); |
| 364 item->tooltip_ = tooltip; | 365 item->tooltip_ = tooltip; |
| 365 } | 366 } |
| 366 | 367 |
| 367 void MenuItemView::SetIcon(const gfx::ImageSkia& icon, int item_id) { | 368 void MenuItemView::SetIcon(const gfx::ImageSkia& icon, int item_id) { |
| 368 MenuItemView* item = GetMenuItemByID(item_id); | 369 MenuItemView* item = GetMenuItemByID(item_id); |
| 369 DCHECK(item); | 370 DCHECK(item); |
| 370 item->SetIcon(icon); | 371 item->SetIcon(icon); |
| 371 } | 372 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 return item; | 442 return item; |
| 442 } | 443 } |
| 443 | 444 |
| 444 char16 MenuItemView::GetMnemonic() { | 445 char16 MenuItemView::GetMnemonic() { |
| 445 if (!GetRootMenuItem()->has_mnemonics_) | 446 if (!GetRootMenuItem()->has_mnemonics_) |
| 446 return 0; | 447 return 0; |
| 447 | 448 |
| 448 size_t index = 0; | 449 size_t index = 0; |
| 449 do { | 450 do { |
| 450 index = title_.find('&', index); | 451 index = title_.find('&', index); |
| 451 if (index != string16::npos) { | 452 if (index != base::string16::npos) { |
| 452 if (index + 1 != title_.size() && title_[index + 1] != '&') { | 453 if (index + 1 != title_.size() && title_[index + 1] != '&') { |
| 453 char16 char_array[] = { title_[index + 1], 0 }; | 454 char16 char_array[] = { title_[index + 1], 0 }; |
| 454 // TODO(jshin): What about Turkish locale? See http://crbug.com/81719. | 455 // TODO(jshin): What about Turkish locale? See http://crbug.com/81719. |
| 455 // If the mnemonic is capital I and the UI language is Turkish, | 456 // If the mnemonic is capital I and the UI language is Turkish, |
| 456 // lowercasing it results in 'small dotless i', which is different | 457 // lowercasing it results in 'small dotless i', which is different |
| 457 // from a 'dotted i'. Similar issues may exist for az and lt locales. | 458 // from a 'dotted i'. Similar issues may exist for az and lt locales. |
| 458 return base::i18n::ToLower(char_array)[0]; | 459 return base::i18n::ToLower(char_array)[0]; |
| 459 } | 460 } |
| 460 index++; | 461 index++; |
| 461 } | 462 } |
| 462 } while (index != string16::npos); | 463 } while (index != base::string16::npos); |
| 463 return 0; | 464 return 0; |
| 464 } | 465 } |
| 465 | 466 |
| 466 MenuItemView* MenuItemView::GetMenuItemByID(int id) { | 467 MenuItemView* MenuItemView::GetMenuItemByID(int id) { |
| 467 if (GetCommand() == id) | 468 if (GetCommand() == id) |
| 468 return this; | 469 return this; |
| 469 if (!HasSubmenu()) | 470 if (!HasSubmenu()) |
| 470 return NULL; | 471 return NULL; |
| 471 for (int i = 0; i < GetSubmenu()->child_count(); ++i) { | 472 for (int i = 0; i < GetSubmenu()->child_count(); ++i) { |
| 472 View* child = GetSubmenu()->child_at(i); | 473 View* child = GetSubmenu()->child_at(i); |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 config.arrow_width) / 2, | 844 config.arrow_width) / 2, |
| 844 config.arrow_width, height()); | 845 config.arrow_width, height()); |
| 845 AdjustBoundsForRTLUI(&arrow_bounds); | 846 AdjustBoundsForRTLUI(&arrow_bounds); |
| 846 canvas->DrawImageInt(GetSubmenuArrowImage(IsSelected()), | 847 canvas->DrawImageInt(GetSubmenuArrowImage(IsSelected()), |
| 847 arrow_bounds.x(), arrow_bounds.y()); | 848 arrow_bounds.x(), arrow_bounds.y()); |
| 848 } | 849 } |
| 849 } | 850 } |
| 850 | 851 |
| 851 void MenuItemView::PaintMinorText(gfx::Canvas* canvas, | 852 void MenuItemView::PaintMinorText(gfx::Canvas* canvas, |
| 852 bool render_selection) { | 853 bool render_selection) { |
| 853 string16 minor_text = GetMinorText(); | 854 base::string16 minor_text = GetMinorText(); |
| 854 if (minor_text.empty()) | 855 if (minor_text.empty()) |
| 855 return; | 856 return; |
| 856 | 857 |
| 857 const gfx::Font& font = GetFont(); | 858 const gfx::Font& font = GetFont(); |
| 858 int available_height = height() - GetTopMargin() - GetBottomMargin(); | 859 int available_height = height() - GetTopMargin() - GetBottomMargin(); |
| 859 int max_accel_width = | 860 int max_accel_width = |
| 860 parent_menu_item_->GetSubmenu()->max_minor_text_width(); | 861 parent_menu_item_->GetSubmenu()->max_minor_text_width(); |
| 861 const MenuConfig& config = GetMenuConfig(); | 862 const MenuConfig& config = GetMenuConfig(); |
| 862 int accel_right_margin = config.align_arrow_and_shortcut ? | 863 int accel_right_margin = config.align_arrow_and_shortcut ? |
| 863 config.arrow_to_edge_padding : item_right_margin_; | 864 config.arrow_to_edge_padding : item_right_margin_; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 } | 977 } |
| 977 int label_start = GetLabelStartForThisItem(); | 978 int label_start = GetLabelStartForThisItem(); |
| 978 | 979 |
| 979 int string_width = font.GetStringWidth(title_); | 980 int string_width = font.GetStringWidth(title_); |
| 980 if (!subtitle_.empty()) | 981 if (!subtitle_.empty()) |
| 981 string_width = std::max(string_width, font.GetStringWidth(subtitle_)); | 982 string_width = std::max(string_width, font.GetStringWidth(subtitle_)); |
| 982 | 983 |
| 983 dimensions.standard_width = string_width + label_start + | 984 dimensions.standard_width = string_width + label_start + |
| 984 item_right_margin_; | 985 item_right_margin_; |
| 985 // Determine the length of the right-side text. | 986 // Determine the length of the right-side text. |
| 986 string16 minor_text = GetMinorText(); | 987 base::string16 minor_text = GetMinorText(); |
| 987 dimensions.minor_text_width = | 988 dimensions.minor_text_width = |
| 988 minor_text.empty() ? 0 : GetFont().GetStringWidth(minor_text); | 989 minor_text.empty() ? 0 : GetFont().GetStringWidth(minor_text); |
| 989 | 990 |
| 990 // Determine the height to use. | 991 // Determine the height to use. |
| 991 dimensions.height = std::max(dimensions.height, | 992 dimensions.height = std::max(dimensions.height, |
| 992 (subtitle_.empty() ? 0 : font.GetHeight()) + | 993 (subtitle_.empty() ? 0 : font.GetHeight()) + |
| 993 font.GetHeight() + GetBottomMargin() + GetTopMargin()); | 994 font.GetHeight() + GetBottomMargin() + GetTopMargin()); |
| 994 dimensions.height = std::max(dimensions.height, | 995 dimensions.height = std::max(dimensions.height, |
| 995 GetMenuConfig().item_min_height); | 996 GetMenuConfig().item_min_height); |
| 996 return dimensions; | 997 return dimensions; |
| 997 } | 998 } |
| 998 | 999 |
| 999 int MenuItemView::GetLabelStartForThisItem() { | 1000 int MenuItemView::GetLabelStartForThisItem() { |
| 1000 int label_start = label_start_ + left_icon_margin_ + right_icon_margin_; | 1001 int label_start = label_start_ + left_icon_margin_ + right_icon_margin_; |
| 1001 if ((type_ == CHECKBOX || type_ == RADIO) && icon_view_) { | 1002 if ((type_ == CHECKBOX || type_ == RADIO) && icon_view_) { |
| 1002 label_start += icon_view_->size().width() + | 1003 label_start += icon_view_->size().width() + |
| 1003 GetMenuConfig().icon_to_label_padding; | 1004 GetMenuConfig().icon_to_label_padding; |
| 1004 } | 1005 } |
| 1005 return label_start; | 1006 return label_start; |
| 1006 } | 1007 } |
| 1007 | 1008 |
| 1008 string16 MenuItemView::GetMinorText() { | 1009 base::string16 MenuItemView::GetMinorText() { |
| 1009 if (id() == kEmptyMenuItemViewID) { | 1010 if (id() == kEmptyMenuItemViewID) { |
| 1010 // Don't query the delegate for menus that represent no children. | 1011 // Don't query the delegate for menus that represent no children. |
| 1011 return string16(); | 1012 return base::string16(); |
| 1012 } | 1013 } |
| 1013 | 1014 |
| 1014 ui::Accelerator accelerator; | 1015 ui::Accelerator accelerator; |
| 1015 if (GetMenuConfig().show_accelerators && GetDelegate() && GetCommand() && | 1016 if (GetMenuConfig().show_accelerators && GetDelegate() && GetCommand() && |
| 1016 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) { | 1017 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) { |
| 1017 return accelerator.GetShortcutText(); | 1018 return accelerator.GetShortcutText(); |
| 1018 } | 1019 } |
| 1019 | 1020 |
| 1020 return minor_text_; | 1021 return minor_text_; |
| 1021 } | 1022 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 } else { | 1062 } else { |
| 1062 const Type& type = menu_item->GetType(); | 1063 const Type& type = menu_item->GetType(); |
| 1063 if (type == CHECKBOX || type == RADIO) | 1064 if (type == CHECKBOX || type == RADIO) |
| 1064 return true; | 1065 return true; |
| 1065 } | 1066 } |
| 1066 } | 1067 } |
| 1067 return false; | 1068 return false; |
| 1068 } | 1069 } |
| 1069 | 1070 |
| 1070 } // namespace views | 1071 } // namespace views |
| OLD | NEW |