forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created TabGroupViews, which manages most of the tab group's visual calculations and updates. TabStrip still paints the views, but it no longer keeps low-level maps to each individual view. TabGroupUnderline can now use TabGroupViews for the bulk of its visual calculations. In the future, TabGroupHighlight will take a similar approach. Change-Id: I894dc03375cb29b42b80bd1273587a41131f1b22 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1925336 Commit-Queue: Connie Wan <connily@chromium.org> Reviewed-by: Taylor Bergquist <tbergquist@chromium.org> Cr-Commit-Position: refs/heads/master@{#721202}
- Loading branch information
Connie Wan
authored and
Commit Bot
committed
Dec 3, 2019
1 parent
bcf1a25
commit a680ace
Showing
9 changed files
with
174 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/views/tabs/tab_group_views.h" | ||
|
||
#include <utility> | ||
|
||
#include "chrome/browser/ui/tabs/tab_strip_model.h" | ||
#include "chrome/browser/ui/views/tabs/tab_group_header.h" | ||
#include "chrome/browser/ui/views/tabs/tab_group_underline.h" | ||
#include "chrome/browser/ui/views/tabs/tab_strip.h" | ||
#include "chrome/browser/ui/views/tabs/tab_strip_controller.h" | ||
#include "third_party/skia/include/core/SkColor.h" | ||
#include "ui/gfx/geometry/rect.h" | ||
|
||
TabGroupViews::TabGroupViews(TabStrip* tab_strip, TabGroupId group) | ||
: tab_strip_(tab_strip), group_(group) { | ||
header_ = std::make_unique<TabGroupHeader>(tab_strip_, group_); | ||
header_->set_owned_by_client(); | ||
|
||
underline_ = std::make_unique<TabGroupUnderline>(this, group_); | ||
underline_->set_owned_by_client(); | ||
} | ||
|
||
TabGroupViews::~TabGroupViews() {} | ||
|
||
void TabGroupViews::UpdateVisuals() { | ||
header_->VisualsChanged(); | ||
underline_->SchedulePaint(); | ||
|
||
const int active_index = tab_strip_->controller()->GetActiveIndex(); | ||
if (active_index != TabStripModel::kNoTab) | ||
tab_strip_->tab_at(active_index)->SchedulePaint(); | ||
} | ||
|
||
gfx::Rect TabGroupViews::GetBounds() const { | ||
const Tab* last_tab = GetLastTabInGroup(); | ||
if (!last_tab) | ||
return header_->bounds(); | ||
|
||
const int start_x = header_->x(); | ||
const int end_x = last_tab->bounds().right(); | ||
|
||
if (end_x <= start_x) | ||
return header_->bounds(); | ||
|
||
const int y = header_->y(); | ||
const int height = header_->height(); | ||
|
||
return gfx::Rect(start_x, y, end_x - start_x, height); | ||
} | ||
|
||
Tab* TabGroupViews::GetLastTabInGroup() const { | ||
const std::vector<int> tabs_in_group = | ||
tab_strip_->controller()->ListTabsInGroup(group_); | ||
|
||
if (tabs_in_group.size() <= 0) | ||
return nullptr; | ||
|
||
const int last_tab_index = tabs_in_group[tabs_in_group.size() - 1]; | ||
return tab_strip_->tab_at(last_tab_index); | ||
} | ||
|
||
SkColor TabGroupViews::GetGroupColor() const { | ||
const TabGroupVisualData* data = | ||
tab_strip_->controller()->GetVisualDataForGroup(group_); | ||
|
||
return data->color(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_UI_VIEWS_TABS_TAB_GROUP_VIEWS_H_ | ||
#define CHROME_BROWSER_UI_VIEWS_TABS_TAB_GROUP_VIEWS_H_ | ||
|
||
#include <memory> | ||
|
||
#include "chrome/browser/ui/tabs/tab_group_id.h" | ||
#include "third_party/skia/include/core/SkColor.h" | ||
#include "ui/gfx/geometry/rect.h" | ||
|
||
class Tab; | ||
class TabGroupHeader; | ||
class TabGroupUnderline; | ||
class TabStrip; | ||
|
||
// The manager of all views associated with a tab group. This handles visual | ||
// calculations and updates. Painting is done in TabStrip. | ||
class TabGroupViews { | ||
public: | ||
TabGroupViews(TabStrip* tab_strip, TabGroupId group); | ||
~TabGroupViews(); | ||
|
||
TabGroupId group() const { return group_; } | ||
TabGroupHeader* header() const { return header_.get(); } | ||
TabGroupUnderline* underline() const { return underline_.get(); } | ||
|
||
// Updates the visuals of each view in preparation for repainting. | ||
void UpdateVisuals(); | ||
|
||
// Returns the bounds of the entire group, including the header and all tabs. | ||
gfx::Rect GetBounds() const; | ||
|
||
// Returns the last tab in the group. Used for some visual calculations. | ||
Tab* GetLastTabInGroup() const; | ||
|
||
// Returns the group color. | ||
SkColor GetGroupColor() const; | ||
|
||
private: | ||
TabStrip* const tab_strip_; | ||
const TabGroupId group_; | ||
std::unique_ptr<TabGroupHeader> header_; | ||
std::unique_ptr<TabGroupUnderline> underline_; | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_GROUP_VIEWS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.