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

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: Fix tests Created 3 years, 11 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
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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 render_text->set_focused(false); 502 render_text->set_focused(false);
503 SchedulePaint(); 503 SchedulePaint();
504 } 504 }
505 View::OnBlur(); 505 View::OnBlur();
506 } 506 }
507 507
508 bool Label::OnMousePressed(const ui::MouseEvent& event) { 508 bool Label::OnMousePressed(const ui::MouseEvent& event) {
509 if (!GetRenderTextForSelectionController()) 509 if (!GetRenderTextForSelectionController())
510 return false; 510 return false;
511 511
512 const bool has_focus = HasFocus();
tapted 2017/01/25 09:11:16 optional: maybe had_focus?
karandeepb 2017/01/25 10:43:55 Done.
513
512 // RequestFocus() won't work when the label has FocusBehavior::NEVER. Hence 514 // RequestFocus() won't work when the label has FocusBehavior::NEVER. Hence
513 // explicitly set the focused view. 515 // explicitly set the focused view.
514 // TODO(karandeepb): If a widget with a label having FocusBehavior::NEVER as 516 // TODO(karandeepb): If a widget with a label having FocusBehavior::NEVER as
515 // the currently focused view (due to selection) was to lose focus, focus 517 // the currently focused view (due to selection) was to lose focus, focus
516 // won't be restored to the label (and hence a text selection won't be drawn) 518 // won't be restored to the label (and hence a text selection won't be drawn)
517 // when the widget gets focus again. Fix this. 519 // when the widget gets focus again. Fix this.
518 // Tracked in https://crbug.com/630365. 520 // Tracked in https://crbug.com/630365.
519 if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && 521 if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) &&
520 GetFocusManager()) { 522 GetFocusManager() && !has_focus) {
521 GetFocusManager()->SetFocusedView(this); 523 GetFocusManager()->SetFocusedView(this);
522 } 524 }
523 525
524 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 526 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
525 if (event.IsOnlyMiddleMouseButton() && GetFocusManager()) 527 if (event.IsOnlyMiddleMouseButton() && GetFocusManager() && !has_focus)
526 GetFocusManager()->SetFocusedView(this); 528 GetFocusManager()->SetFocusedView(this);
527 #endif 529 #endif
528 530
529 return selection_controller_->OnMousePressed(event, false); 531 return selection_controller_->OnMousePressed(
532 event, false, has_focus ? SelectionController::FOCUSED
533 : SelectionController::UNFOCUSED);
530 } 534 }
531 535
532 bool Label::OnMouseDragged(const ui::MouseEvent& event) { 536 bool Label::OnMouseDragged(const ui::MouseEvent& event) {
533 if (!GetRenderTextForSelectionController()) 537 if (!GetRenderTextForSelectionController())
534 return false; 538 return false;
535 539
536 return selection_controller_->OnMouseDragged(event); 540 return selection_controller_->OnMouseDragged(event);
537 } 541 }
538 542
539 void Label::OnMouseReleased(const ui::MouseEvent& event) { 543 void Label::OnMouseReleased(const ui::MouseEvent& event) {
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 .WriteText(GetSelectedText()); 1018 .WriteText(GetSelectedText());
1015 } 1019 }
1016 1020
1017 void Label::BuildContextMenuContents() { 1021 void Label::BuildContextMenuContents() {
1018 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); 1022 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY);
1019 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, 1023 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL,
1020 IDS_APP_SELECT_ALL); 1024 IDS_APP_SELECT_ALL);
1021 } 1025 }
1022 1026
1023 } // namespace views 1027 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/textfield/textfield.cc » ('j') | ui/views/controls/textfield/textfield.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698