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

Side by Side Diff: ui/views/controls/label.cc

Issue 2650963002: MacViews: Select all text on right clicking an unfocused text view. (Closed)
Patch Set: Nit Created 3 years, 10 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
« no previous file with comments | « no previous file | ui/views/controls/textfield/textfield.cc » ('j') | 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) 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/label.h" 5 #include "ui/views/controls/label.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 render_text->set_focused(false); 506 render_text->set_focused(false);
507 SchedulePaint(); 507 SchedulePaint();
508 } 508 }
509 View::OnBlur(); 509 View::OnBlur();
510 } 510 }
511 511
512 bool Label::OnMousePressed(const ui::MouseEvent& event) { 512 bool Label::OnMousePressed(const ui::MouseEvent& event) {
513 if (!GetRenderTextForSelectionController()) 513 if (!GetRenderTextForSelectionController())
514 return false; 514 return false;
515 515
516 const bool had_focus = HasFocus();
517
516 // RequestFocus() won't work when the label has FocusBehavior::NEVER. Hence 518 // RequestFocus() won't work when the label has FocusBehavior::NEVER. Hence
517 // explicitly set the focused view. 519 // explicitly set the focused view.
518 // TODO(karandeepb): If a widget with a label having FocusBehavior::NEVER as 520 // TODO(karandeepb): If a widget with a label having FocusBehavior::NEVER as
519 // the currently focused view (due to selection) was to lose focus, focus 521 // the currently focused view (due to selection) was to lose focus, focus
520 // won't be restored to the label (and hence a text selection won't be drawn) 522 // won't be restored to the label (and hence a text selection won't be drawn)
521 // when the widget gets focus again. Fix this. 523 // when the widget gets focus again. Fix this.
522 // Tracked in https://crbug.com/630365. 524 // Tracked in https://crbug.com/630365.
523 if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && 525 if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) &&
524 GetFocusManager()) { 526 GetFocusManager() && !had_focus) {
525 GetFocusManager()->SetFocusedView(this); 527 GetFocusManager()->SetFocusedView(this);
526 } 528 }
527 529
528 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 530 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
529 if (event.IsOnlyMiddleMouseButton() && GetFocusManager()) 531 if (event.IsOnlyMiddleMouseButton() && GetFocusManager() && !had_focus)
530 GetFocusManager()->SetFocusedView(this); 532 GetFocusManager()->SetFocusedView(this);
531 #endif 533 #endif
532 534
533 return selection_controller_->OnMousePressed(event, false); 535 return selection_controller_->OnMousePressed(
536 event, false, had_focus ? SelectionController::FOCUSED
537 : SelectionController::UNFOCUSED);
534 } 538 }
535 539
536 bool Label::OnMouseDragged(const ui::MouseEvent& event) { 540 bool Label::OnMouseDragged(const ui::MouseEvent& event) {
537 if (!GetRenderTextForSelectionController()) 541 if (!GetRenderTextForSelectionController())
538 return false; 542 return false;
539 543
540 return selection_controller_->OnMouseDragged(event); 544 return selection_controller_->OnMouseDragged(event);
541 } 545 }
542 546
543 void Label::OnMouseReleased(const ui::MouseEvent& event) { 547 void Label::OnMouseReleased(const ui::MouseEvent& event) {
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 .WriteText(GetSelectedText()); 1032 .WriteText(GetSelectedText());
1029 } 1033 }
1030 1034
1031 void Label::BuildContextMenuContents() { 1035 void Label::BuildContextMenuContents() {
1032 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); 1036 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY);
1033 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, 1037 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL,
1034 IDS_APP_SELECT_ALL); 1038 IDS_APP_SELECT_ALL);
1035 } 1039 }
1036 1040
1037 } // namespace views 1041 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/textfield/textfield.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698