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

Unified Diff: ui/views/controls/scroll_view.cc

Issue 2715813002: Change focus indicator for TableView and TreeView. (Closed)
Patch Set: rename 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/scroll_view.h ('k') | ui/views/controls/table/table_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/scroll_view.cc
diff --git a/ui/views/controls/scroll_view.cc b/ui/views/controls/scroll_view.cc
index f457cb7c67ccec7191db74cd14b80f495055e4cb..d58f8478857fee42f0b5e3a51b8a948b665f3195 100644
--- a/ui/views/controls/scroll_view.cc
+++ b/ui/views/controls/scroll_view.cc
@@ -7,6 +7,7 @@
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/macros.h"
+#include "ui/base/material_design/material_design_controller.h"
#include "ui/events/event.h"
#include "ui/gfx/canvas.h"
#include "ui/native_theme/native_theme.h"
@@ -31,23 +32,7 @@ const base::Feature kToolkitViewsScrollWithLayers {
#endif
};
-// Subclass of ScrollView that resets the border when the theme changes.
-class ScrollViewWithBorder : public views::ScrollView {
- public:
- ScrollViewWithBorder() {}
-
- // View overrides;
- void OnNativeThemeChanged(const ui::NativeTheme* theme) override {
- SetBorder(CreateSolidBorder(
- 1,
- theme->GetSystemColor(ui::NativeTheme::kColorId_UnfocusedBorderColor)));
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ScrollViewWithBorder);
-};
-
-class ScrollCornerView : public views::View {
+class ScrollCornerView : public View {
public:
ScrollCornerView() {}
@@ -196,7 +181,21 @@ ScrollView::~ScrollView() {
// static
ScrollView* ScrollView::CreateScrollViewWithBorder() {
- return new ScrollViewWithBorder();
+ auto scroll_view = new ScrollView();
+ scroll_view->AddBorder();
+ return scroll_view;
+}
+
+// static
+ScrollView* ScrollView::GetScrollViewForContents(View* contents) {
+ View* grandparent =
+ contents->parent() ? contents->parent()->parent() : nullptr;
+ if (!grandparent || grandparent->GetClassName() != ScrollView::kViewClassName)
+ return nullptr;
+
+ auto scroll_view = static_cast<ScrollView*>(grandparent);
+ DCHECK_EQ(contents, scroll_view->contents());
+ return scroll_view;
}
void ScrollView::SetContents(View* a_view) {
@@ -269,14 +268,21 @@ void ScrollView::SetVerticalScrollBar(ScrollBar* vert_sb) {
vert_sb_ = vert_sb;
}
-void ScrollView::SetHasFocusRing(bool has_focus_ring) {
- if (has_focus_ring == (focus_ring_ != nullptr))
+void ScrollView::SetHasFocusIndicator(bool has_focus_indicator) {
+ if (has_focus_indicator == draw_focus_indicator_)
return;
- if (has_focus_ring) {
- focus_ring_ = FocusRing::Install(this);
+ draw_focus_indicator_ = has_focus_indicator;
+
+ if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
+ DCHECK_EQ(draw_focus_indicator_, !focus_ring_);
+ if (has_focus_indicator) {
+ focus_ring_ = FocusRing::Install(this);
+ } else {
+ FocusRing::Uninstall(this);
+ focus_ring_ = nullptr;
+ }
} else {
- FocusRing::Uninstall(this);
- focus_ring_ = nullptr;
+ UpdateBorder();
}
SchedulePaint();
}
@@ -517,6 +523,10 @@ const char* ScrollView::GetClassName() const {
return kViewClassName;
}
+void ScrollView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
+ UpdateBorder();
+}
+
void ScrollView::ScrollToPosition(ScrollBar* source, int position) {
if (!contents_)
return;
@@ -736,6 +746,23 @@ void ScrollView::ScrollHeader() {
}
}
+void ScrollView::AddBorder() {
+ draw_border_ = true;
+ UpdateBorder();
+}
+
+void ScrollView::UpdateBorder() {
+ if (!draw_border_ || !GetWidget())
+ return;
+
+ SetBorder(CreateSolidBorder(
+ 1,
+ GetNativeTheme()->GetSystemColor(
+ draw_focus_indicator_
+ ? ui::NativeTheme::kColorId_FocusedBorderColor
+ : ui::NativeTheme::kColorId_UnfocusedBorderColor)));
+}
+
// VariableRowHeightScrollHelper ----------------------------------------------
VariableRowHeightScrollHelper::VariableRowHeightScrollHelper(
« no previous file with comments | « ui/views/controls/scroll_view.h ('k') | ui/views/controls/table/table_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698